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.

26 lines
550 B

#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int w[N][N];
int f[N][N];
int n, m;
int main() {
int T;
cin >> T;
while (T--) {
memset(f, 0, sizeof f);
cin >> n >> m;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
cin >> w[i][j];
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
f[i][j] = max(f[i - 1][j], f[i][j - 1]) + w[i][j];
printf("%d\n", f[n][m]);
}
return 0;
}