Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- long MAX(long a,long b,long c)
- {
- if(a>b)
- {
- if(a>c) return a;
- else return c;
- }
- else
- {
- if(b>c) return b;
- else return c;
- }
- }
- long mat[1010][1010],r,c,count;
- long DP(long i,long j)
- {
- if(i==r|| j==c) return 0;
- if(i<0 || j<0) return 0;
- count=mat[i][j]+MAX(DP(i+1,j-1),DP(i+1,j),DP(i+1,j+1));
- return count;
- }
- int main()
- {
- long n,i,j,cnt;
- while(cin>>r>>c)
- {
- for(i=0;i<r;i++)
- {
- for(j=0;j<c;j++)
- {
- cin>>mat[i][j];
- }
- }
- cnt=0;
- for(i=0;i<c;i++)
- {
- count=0;
- n=DP(0,i);
- //cout<<n<<endl;
- if(n>cnt) cnt=n;
- }
- cout<<cnt<<endl;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment