一、题目链接
二、题目分析
(一)算法标签
动态规划 数字三角形
(二)解题思路
三、AC代码
解法一:
#include <iostream>
using namespace std;
const int N = 110;
int n, m;
int f[N][N], w[N][N];
int main()
{
int R;
scanf("%d", &R);
while (R -- )
{
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i ++ )
for (int j = 1; j <= m; j ++ )
{
scanf("%d", &w[i][j]);
f[i][j] = max(f[i - 1][j], f[i][j - 1]) + w[i][j];
}
printf("%d\n", f[n][m]);
}
return 0;
}