Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <cstdio>
- #include <algorithm>
- #include <cmath>
- #include <iomanip>
- #include <string>
- #include <cstring>
- #include <fstream>
- using namespace std;
- long long a[300][300];
- int main()
- {
- int n,m;
- cin>>n>>m;
- for (int i=0; i<n; i++)
- for (int j=0; j<m; j++)
- cin>>a[i][j];
- for (int i=1; i<n; i++)
- for (int j=0; j<m; j++)
- {
- if (j==0)
- {
- a[i][j]+=max(a[i-1][j], a[i-1][j+1]);
- }
- else
- if (j==m-1)
- {
- a[i][j]+=max(a[i-1][j], a[i-1][j-1]);
- }
- else
- {
- a[i][j]+=max(a[i-1][j], max( a[i-1][j-1], a[i-1][j+1]));
- }
- }
- long long res=a[n-1][0];
- for (int i=1; i<m; i++)
- {
- if (res<a[n-1][i])
- res=a[n-1][i];
- }
- cout<<res<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement