Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <iomanip>
- using namespace std;
- int max_abc(int a,int b, int c)
- {
- return max(a,max(b,c));
- };
- int main()
- {
- int n,m,i,j,max;
- cin>>n>>m;
- int a[n+2][m+2], b[n+2][m+2];
- for (j=0; j<=m+1;j++)
- b[0][j] = b[n+1][j] = 0;
- for (i=0; i<=n+1; i++)
- b[i][0] = b[i][m+1] = 0;
- for (i=1; i<=n; i++)
- for (j=1; j<=m; j++)
- cin>>a[i][j];
- max = a[1][1];
- for (i=1; i<=n; i++)
- {
- if (max < a[i][1]) max = a[i][1];
- b[i][1] = a[i][1];
- }
- for (j=1; j<=m; j++)
- {
- for (i=1; i<=n; i++)
- b[i][j] = a[i][j] + max_abc(b[i-1][j-1], b[i][j-1], b[i+1][j-1]);
- max = b[1][j];
- for (i=2; i<=n; i++)
- if (max < b[i][j]) max = b[i][j];
- }
- cout<<max;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement