Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Jun 13th, 2018 44 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. long MAX(long a,long b,long c)
  5. {
  6.     if(a>b)
  7.     {
  8.         if(a>c) return a;
  9.         else return c;
  10.     }
  11.     else
  12.     {
  13.         if(b>c) return b;
  14.         else return c;
  15.     }
  16. }
  17. long mat[1010][1010],r,c,count;
  18.  
  19. long DP(long i,long j)
  20. {
  21.     if(i==r|| j==c) return 0;
  22.     if(i<0 || j<0) return 0;
  23.     count=mat[i][j]+MAX(DP(i-1,j+1),DP(i,j+1),DP(i+1,j+1));
  24.     return count;
  25. }
  26.  
  27. int main()
  28. {
  29.     long n,i,j,cnt;
  30.  
  31.     while(cin>>r>>c)
  32.     {
  33.         for(i=0;i<r;i++)
  34.         {
  35.             for(j=0;j<c;j++)
  36.             {
  37.                 cin>>mat[i][j];
  38.             }
  39.         }
  40.         cnt=0;
  41.         for(i=0;i<r;i++)
  42.         {
  43.             count=0;
  44.             n=DP(i,0);
  45.             cout<<n<<endl;
  46.             if(n>cnt) cnt=n;
  47.         }
  48.         cout<<cnt<<endl;
  49.     }
  50.     return 0;
  51. }
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