You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
748 B

#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int w[N][N];
int f[N];
int n, m;
int main() {
int T;
scanf("%d", &T);
while (T--) {
memset(f, 0, sizeof f);
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
scanf("%d", &w[i][j]);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
if (i == 1 && j == 1) // 递推的出发点,采用特判的办法手动维护,其它的靠关系式递推完成
f[j] = w[i][j];
else
f[j] = max(f[j], f[j - 1]) + w[i][j];
printf("%d\n", f[m]);
}
return 0;
}