-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC-Vacation.cpp
More file actions
67 lines (61 loc) · 1.07 KB
/
C-Vacation.cpp
File metadata and controls
67 lines (61 loc) · 1.07 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
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define intl long long
void fastio()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int main()
{
intl n;
cin>>n;
intl a[n+1][4];
for(intl i=1;i<=n;i++)
{
for(intl j=1;j<=3;j++)
{
cin>>a[i][j];
}
}
intl dp[n+1][4];
dp[1][1]=a[1][1];
dp[1][2]=a[1][2];
dp[1][3]=a[1][3];
if(n>1){
for(intl i=2;i<=n;i++)
{
for(intl j=1;j<=3;j++)
{
if(j==1)
{
dp[i][j]=a[i][j]+max(dp[i-1][j+1],dp[i-1][j+2]);
}
if(j==2)
{
dp[i][j]=a[i][j]+max(dp[i-1][j-1],dp[i-1][j+1]);
}
if(j==3)
{
dp[i][j]=a[i][j]+max(dp[i-1][j-1],dp[i-1][j-2]);
}
}
}
cout<<max(dp[n][3],max(dp[n][2],dp[n][1]));
}else{
cout<<max(dp[n][3],max(dp[n][2],dp[n][1]));
}
// for(intl i=1;i<=n;i++)
// {
// for(intl j=1;j<=3;j++)
// {
// cout<<dp[i][j]<<" ";
// }
// cout<<endl;
// }
}