AcWing 1015. 摘花生
原题链接
简单
作者:
hegehog
,
2020-07-06 18:23:54
,
所有人可见
,
阅读 454
C++代码
#include <iostream>
using namespace std;
const int N = 105;
int t;
int m[N][N];
int f[N][N];
int r,c;
int main()
{
cin >> t;
while(t -- )
{
cin >> r >> c;
for(int i = 1; i <= r; i ++)
for(int j = 1; j <= c; j ++)
cin >> m[i][j];
for(int i = 0; i <= r; i ++)
f[i][0] = 0;
for(int j = 0; j <= c; j ++)
f[0][j] = 0;
for(int i = 1; i <=r; i++)
for(int j = 1; j <= c; j ++)
f[i][j] = max(f[i-1][j], f[i][j-1]) + m[i][j];
cout << f[r][c] << endl;
}
return 0;
}
//f[i,j]
//集合:从起点到(i,j)的所有可行路径
//属性:MAXN
//状态计算:f[i,j] = max(f[i-1,j], f[i,j-1]) + m[i][j]