1015. 摘花生
2021/8/4 6:06:23
本文主要是介绍1015. 摘花生,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
https://www.acwing.com/problem/content/description/1017/
二维地图的dp,对于某一个而言,只能向右,或者向下,除了边界,每一个都继承最优的选项即可。
1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 ll t,r,c; 5 const ll N=1e3+520; 6 ll a[N][N]; 7 int main() 8 { 9 scanf("%lld",&t); 10 while(t--) 11 { 12 scanf("%lld%lld",&r,&c); 13 for(int i=1;i<=r;i++) 14 { 15 for(int j=1;j<=c;j++) 16 { 17 scanf("%lld",&a[i][j]); 18 if(i==1) a[i][j]+=a[1][j-1]; 19 else if(j==1) a[i][j]+=a[i-1][j]; 20 else a[i][j]+=max(a[i-1][j],a[i][j-1]); 21 } 22 } 23 cout<<a[r][c]<<'\n'; 24 } 25 return 0; 26 }
这篇关于1015. 摘花生的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-10-05小米13T Pro系统合集:性能与摄影的极致融合,值得你升级的系统ROM
- 2024-10-01基于Python+Vue开发的医院门诊预约挂号系统
- 2024-10-01基于Python+Vue开发的旅游景区管理系统
- 2024-10-01RestfulAPI入门指南:打造简单易懂的API接口
- 2024-10-01初学者指南:了解和使用Server Action
- 2024-10-01Server Component入门指南:搭建与配置详解
- 2024-10-01React 中使用 useRequest 实现数据请求
- 2024-10-01使用 golang 将ETH账户的资产平均分散到其他账户
- 2024-10-01JWT用户校验课程:从入门到实践
- 2024-10-01Server Component课程入门指南