Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- const int maxn = 1e5 + 10;
- const int INF = 2e9 + 5;
- int n,k;
- int a[100000],b[100000],c[100000];
- int dp[100000][4];
- int rec(int poz, int prev_akt){
- if (poz==n){
- return 0;
- }
- if (dp[poz][prev_akt]!=-1){
- return dp[poz][prev_akt];
- }
- int maximum=0;
- int cost=0;
- for (int i=1;i<4;i++){
- if (prev_akt== i){
- continue
- ;}
- else {
- if (i==1){
- cost=a[poz]
- ;}
- else if(i==2){
- cost= b[poz];
- }
- else {
- cost=c[poz];
- }
- maximum =max (maximum,rec (poz+1,i)+cost);
- }
- }
- dp[poz][prev_akt]=maximum;
- return maximum;
- }
- int main(){
- cin>>n;
- for (int i=0;i<n;i++){
- cin>>a[i]>>b[i]>>c[i];
- for (int j=1;j<4;j++){
- dp[i][j]=-1;
- }
- }
- int maximum=0;
- for (int i=1;i<4;i++){
- maximum =max (maximum,rec (0,i));
- }
- cout<<maximum;
- }
Advertisement
Add Comment
Please, Sign In to add comment