Guest User

Untitled

a guest
Jun 13th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  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+1,j),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<c;i++)
  42. {
  43. count=0;
  44. n=DP(0,i);
  45. //cout<<n<<endl;
  46. if(n>cnt) cnt=n;
  47. }
  48. cout<<cnt<<endl;
  49. }
  50. return 0;
  51. }
Add Comment
Please, Sign In to add comment