fork download
  1. /// no time to waste
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. int n, m;
  6. long long a[11][11];
  7. long long res = 0;
  8.  
  9. void TRY(int u, int v, long long sum) {
  10. if(u == n && v == m) {
  11. res = max(res, sum);
  12. return;
  13. }
  14.  
  15. if(u < n) TRY(u + 1, v, a[u + 1][v] + sum);
  16. if(v < m) TRY(u, v + 1, a[u][v + 1] + sum);
  17. return;
  18. }
  19.  
  20. int32_t main() {
  21. ios::sync_with_stdio(false);
  22. cin.tie(0), cout.tie(0);
  23. freopen("mecung.inp", "r", stdin);
  24. freopen("mecung.out", "w", stdout);
  25.  
  26. cin >> n >> m;
  27. for(int i=1;i<=n;i++) {
  28. for(int j=1;j<=m;j++) cin >> a[i][j];
  29. }
  30.  
  31. TRY(1, 1, a[1][1]);
  32. cout << res;
  33. return 0;
  34. }
Success #stdin #stdout 0.01s 5252KB
stdin
3 3
1 2 3
0 4 1
2 0 1
stdout
Standard output is empty