1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| #include<cstring> #include<iostream> using namespace std;
const int N = 105; int a[2][N], f[2][N], q, n, m;
int main() { cin >> q; while(q--){ cin >> n >> m;
for(int i = 1; i <= n; i++){ for(int j = 1; j <= m; j++){ cin >> a[i&1][j]; f[i&1][j] = max(f[i&1][j-1], f[(i-1)&1][j]) + a[i&1][j]; } } cout << f[n&1][m] << endl;
memset(f, 0, sizeof f); } }
|