Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int MAX=1e5;
- int n,arr[MAX+2][3];
- long long dp[MAX+3][3];
- long long solve(int ind,int last){
- if(ind==n) return 0;
- if(dp[ind][last]!=-1) return dp[ind][last];
- long long ans=-1e17;
- if(last!=0) ans=max(ans,solve(ind+1,0)+arr[ind][0]);
- if(last!=1) ans=max(ans,solve(ind+1,1)+arr[ind][1]);
- if(last!=2) ans=max(ans,solve(ind+1,2)+arr[ind][2]);
- return dp[ind][last]=ans;
- }
- int main()
- {
- cin>>n;
- for(int i=0;i<n;i++){
- for(int j=0;j<3;j++)
- cin>>arr[i][j];
- }
- memset(dp,-1,sizeof(dp));
- cout<<solve(0,4);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement