AcWing 1015. 摘花生
原题链接
简单
作者:
兜兜里有糖
,
2024-12-20 17:48:53
,
所有人可见
,
阅读 2
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
void solve()
{
int r, c;
cin >> r >> c;
vector<vector<int>> mp(r + 1, vector<int>(c + 1)), dp(r + 1, vector<int>(c + 1));
for (int i = 1; i <= r; i++)
{
for (int j = 1; j <= c; j++)
{
cin >> mp[i][j];
}
}
for (int i = 1; i <= r; i++)
{
for (int j = 1; j <= c; j++)
{
dp[i][j] = mp[i][j] + max(dp[i - 1][j], dp[i][j - 1]);
}
}
cout << dp[r][c] << '\n';
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int _ = 1;
cin >> _;
while (_--)
{
solve();
}
return 0;
}