-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode_for_problem_C(Vacation).cpp
More file actions
157 lines (116 loc) · 2.83 KB
/
code_for_problem_C(Vacation).cpp
File metadata and controls
157 lines (116 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
ATCODER DP : PROBLEM C (Vacation)
PROBLEM LINK : https://atcoder.jp/contests/dp/tasks/dp_c
*/
#include<algorithm>
#include<bits/stdc++.h>
#define ll long long int
#define dbl long double
#define loop(i,ed) for(ll i=0;i<ed;i++)
#define rloop(i,ed) for(ll i=ed-1;i>=0;i--)
#define aloop(it,a) for(auto it:a)
#define test(tc) ll tc;cin>>tc;while(tc--)
#define debo ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define vi vector<ll>
#define sz size()
#define bs binary_search
#define setBits __builtin_popcountll
#define mod 1000000007
#define yos cout<<"YES"<<endl
#define nos cout<<"NO"<<endl
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define F first
#define S second
#define vep vector<pair<ll,ll>>
#define all(v) v.begin(),v.end()
#define tos to_string
#define iss(v) is_sorted(all(v))
#define sp " "
#define mem(a,i) memset(a,i,sizeof(a))
using namespace std;
/*
" " =>32
A=>65
a=>97
*/
bool isPrime(ll n)
{
if (n <= 1) return false;
if (n <= 3) return true;
if (n % 2 == 0 || n % 3 == 0) return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
bool IsPalindrome( string str)
{
if (str.empty())
return false;
ll i = 0; // first characters
ll j = str.length() - 1; // last character
while (i < j)
{
if (str[i] != str[j])
{
return false;
}
i++;
j--;
}
return true;
}
// Binary Exponentiation fun to calculate pow in 0(logN)
ll binpow(ll a, ll b) {
if (b == 0)
return 1;
ll res = binpow(a, b / 2);
if (b % 2)
return (res * res * a);
return (res * res);
}
ll n;
ll a[100000+5][4];
ll dp[100000+5][4];
ll w=0,x=1,y=2,z=3;
ll func(ll ind, ll flag) {
if (ind == n) return 0;
if (dp[ind][flag] != -1) return dp[ind][flag];
ll maxi = 0;
if (flag == w) {
maxi = max(maxi, a[ind][1] + func(ind + 1, x));
maxi = max(maxi, a[ind][2] + func(ind + 1, y));
maxi = max(maxi, a[ind][3] + func(ind + 1, z));
}
else if (flag == x) {
maxi = max(maxi, a[ind][2] + func(ind + 1, y));
maxi = max(maxi, a[ind][3] + func(ind + 1, z));
}
else if (flag == y) {
maxi = max(maxi, a[ind][1] + func(ind + 1, x));
maxi = max(maxi, a[ind][3] + func(ind + 1, z));
}
else {
maxi = max(maxi, a[ind][1] + func(ind + 1, x));
maxi = max(maxi, a[ind][2] + func(ind + 1, y));
}
return dp[ind][flag] = maxi;
}
signed main(){
debo;
// test(tc){
cin>>n;
loop(i,n)
{
for(ll j=1;j<=3;j++)
{
cin>>a[i][j];
}
}
mem(dp,-1);
cout<<func(w,w);
// }
return 0;
}