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.
24 lines
543 B
24 lines
543 B
#include <bits/stdc++.h>
|
|
|
|
using namespace std;
|
|
// 通过了 2/10个数据
|
|
const int N = 110;
|
|
int w[N][N];
|
|
int n, m;
|
|
int dfs(int x, int y) {
|
|
if (x == n && y == m) return w[n][m];
|
|
if (x > n || y > m) return 0;
|
|
return max(dfs(x + 1, y), dfs(x, y + 1)) + w[x][y];
|
|
}
|
|
int main() {
|
|
int T;
|
|
cin >> T;
|
|
while (T--) {
|
|
cin >> n >> m;
|
|
for (int i = 1; i <= n; i++)
|
|
for (int j = 1; j <= m; j++)
|
|
cin >> w[i][j];
|
|
printf("%d \n", dfs(1, 1));
|
|
}
|
|
return 0;
|
|
} |