acwing 1015. 摘花生
题目链接https://www.acwing.com/problem/content/1017/
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int dp[110][110],a[110][110];
int main() {
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
memset(dp, 0, sizeof(dp));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> a[i][j];
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (i > 1)
dp[i][j] = max(dp[i][j], dp[i - 1][j]);
if (j > 1)
dp[i][j] = max(dp[i][j], dp[i][j - 1]);
dp[i][j] += a[i][j];
}
}
cout << dp[n][m] << endl;
}
return 0;
}