Advertisement
Guest User

Untitled

a guest
Apr 20th, 2018
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int t;
  8. cin >> t;
  9. while (t-- > 0) {
  10. int w, k;
  11. cin>> w >> k;
  12. int a[w][k];
  13. for (int i = 0; i < w; i++)
  14. for (int j = 0; j < k; j++)
  15. cin >> a[i][j];
  16. ;
  17. int c[w][k];
  18. c[0][0] = a[0][0];
  19. for (int i = 1; i < w; i++)
  20. c[i][0] = a[i][0] + c[i-1][0];
  21. for (int j = 1; j < k; j++)
  22. c[0][j] = a[0][j] + c[0][j-1];
  23. for (int i = 1; i < w; i++)
  24. for (int j = 1; j < k; j++)
  25. c[i][j] = a[i][j] + max(c[i-1][j], c[i][j-1]);
  26. ;
  27.  
  28. cout << c[w-1][k-1] << endl;
  29.  
  30.  
  31. }
  32.  
  33.  
  34. return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement