摘花生
给一个2d矩阵, 只能往下往右走, 每个格上有数字, 求最大能拿多少数字.
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 110;
int dp[N][N];
int m[N][N];
int main() {
int t;
cin >> t;
while (t--)
{
int row,col;
cin >> row;
cin >> col;
for (auto i = 1; i <= row; i++)
{
for (auto j = 1; j <= col; j++)
{
cin >> m[i][j];
}
}
for (auto i = 1; i <= row; i++)
{
for(auto j = 1; j <= col; j++) {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) + m[i][j]; // dp[1][1] = max(dp[0][1],dp[1][0]) +
}
}
cout << dp[row][col] << endl;
}
}