Advertisement
YEZAELP

o57_oct_c2_pacman

Jan 13th, 2022
1,061
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. const int inf = 1e9;
  5. const int N = 1e3 + 10;
  6. int ar[N][N], dp[N][N][3];
  7.  
  8. int main(){
  9.  
  10.     int n, m;
  11.     scanf("%d %d", &n, &m);
  12.  
  13.     for(int i=1;i<=n;i++){
  14.         for(int j=1;j<=m;j++){
  15.             scanf("%d", &ar[i][j]);
  16.         }
  17.     }
  18.  
  19.     int ans = 0;
  20.     for(int i=1;i<=n;i++){
  21.         for(int j=1;j<=m;j++){
  22.             dp[i][j][0] = max({ i > 1 ? dp[i - 1][j][0] : 0 , j > 1 ? dp[i][j - 1][0] : 0 ,
  23.                                 i > 1 ? dp[i - 1][j][1] : 0 , j > 1 ? dp[i][j - 1][1] : 0 ,
  24.                                 i > 1 ? dp[i - 1][j][2] : 0 , j > 1 ? dp[i][j - 1][2] : 0 });
  25.             dp[i][j][1] = ar[i][j] + max({ i > 1 ? dp[i - 1][j][0] : 0 , j > 1 ? dp[i][j - 1][0] : 0 });
  26.             dp[i][j][2] = ar[i][j] + max({ i > 1 ? dp[i - 1][j][1] : 0 , j > 1 ? dp[i][j - 1][1] : 0});
  27.         }
  28.     }
  29.  
  30.     printf("%d", max({ dp[n][m][0] , dp[n][m][1] , dp[n][m][2] }));
  31.  
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement