Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int t;
- cin >> t;
- while (t-- > 0) {
- int w, k;
- cin>> w >> k;
- int a[w][k];
- for (int i = 0; i < w; i++)
- for (int j = 0; j < k; j++)
- cin >> a[i][j];
- ;
- int c[w][k];
- c[0][0] = a[0][0];
- for (int i = 1; i < w; i++)
- c[i][0] = a[i][0] + c[i-1][0];
- for (int j = 1; j < k; j++)
- c[0][j] = a[0][j] + c[0][j-1];
- for (int i = 1; i < w; i++)
- for (int j = 1; j < k; j++)
- c[i][j] = a[i][j] + max(c[i-1][j], c[i][j-1]);
- ;
- cout << c[w-1][k-1] << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement