Advertisement
Guest User

Untitled

a guest
Feb 17th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. const int MAX=1e5;
  5. int n,arr[MAX+2][3];
  6. long long dp[MAX+3][3];
  7.  
  8. long long solve(int ind,int last){
  9. if(ind==n) return 0;
  10. if(dp[ind][last]!=-1) return dp[ind][last];
  11. long long ans=-1e17;
  12. if(last!=0) ans=max(ans,solve(ind+1,0)+arr[ind][0]);
  13. if(last!=1) ans=max(ans,solve(ind+1,1)+arr[ind][1]);
  14. if(last!=2) ans=max(ans,solve(ind+1,2)+arr[ind][2]);
  15. return dp[ind][last]=ans;
  16. }
  17.  
  18. int main()
  19. {
  20. cin>>n;
  21. for(int i=0;i<n;i++){
  22. for(int j=0;j<3;j++)
  23. cin>>arr[i][j];
  24. }
  25. memset(dp,-1,sizeof(dp));
  26. cout<<solve(0,4);
  27. return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement