fork download
  1. #include <iostream>
  2. using namespace std;
  3. #define int long long
  4. int a[5][5];
  5. int dp[5][5];
  6. signed main() {
  7. for(int i=1;i<=4;i++){
  8. for(int j=1;j<=4;j++){
  9. cin>>a[i][j];
  10. dp[i][j]=a[i][j]+max(dp[i-1][j],dp[i][j-1]);
  11. }
  12. }
  13. cout<<dp[4][4];
  14. return 0;
  15. }
Success #stdin #stdout 0.01s 5316KB
stdin
2 2 2 1
1 1 2 1
1 1 2 1
1 1 2 2
stdout
14