SHARE
TWEET

Untitled

a guest Dec 5th, 2019 101 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #define MAX(a,b) ((a) > (b) ? (a) : (b))
  5.  
  6. int main(void){
  7.     int n, m;
  8.     scanf("%d %d", &n, &m);
  9.     long long  int mas[n+2][m+2], d[n+2][m+2];
  10.     int i = 0, j = 0;
  11.     for (; i < n + 2; i++){
  12.         for(j = 0; j < m + 2; j++){
  13.             d[i][j] =0;
  14.         }
  15.     }
  16.     for( i= 0; i < n; i++)
  17.         for (j= 0; j < m; j++)
  18.             scanf("%lld", &mas[i][j]);
  19.    
  20.     for ( i = 1; i < n+1; i++){
  21.         d[i][1] = mas[i - 1][0];
  22.  
  23.     }
  24.     for (j = 2; j < m+1; j++){
  25.         for (i = 1; i < n + 1; i++)
  26.             d[i][j] = mas[i - 1][j-1] + MAX(MAX(d[i-1][j-1], d[i+1][j-1]), d[i][j-1]);
  27.     }
  28.     //            
  29.     long long int lm = 0;
  30.     for( i= 1; i < n+1; i++){
  31.         if (d[i][m]  > lm) lm = d[i][m];
  32.    
  33.     }
  34.     printf("%lld", lm);
  35.  
  36.  
  37. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top