-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathatDPC.cpp
More file actions
38 lines (28 loc) · 790 Bytes
/
Copy pathatDPC.cpp
File metadata and controls
38 lines (28 loc) · 790 Bytes
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
/*
* Contest : AtCoder Educational DP Contest
* Problem : C - Vacation
* Link : https://atcoder.jp/contests/dp/tasks/dp_c
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fastio ios::sync_with_stdio(0); cin.tie(0);
int main() {
fastio
int n; cin >> n;
ll v[n][3];
for (int i = 0; i < n; ++i) cin >> v[i][0] >> v[i][1] >> v[i][2];
ll dp[n][3];
dp[0][0] = v[0][0];
dp[0][1] = v[0][1];
dp[0][2] = v[0][2];
for (int i = 1; i < n; ++i) {
dp[i][0] = v[i][0] + max(dp[i - 1][1], dp[i - 1][2]);
dp[i][1] = v[i][1] + max(dp[i - 1][0], dp[i - 1][2]);
dp[i][2] = v[i][2] + max(dp[i - 1][0], dp[i - 1][1]);
}
ll ans = 0;
for (int i = 0; i < 3; ++i) { ans = max(ans, dp[n - 1][i]); }
cout << ans << "\n";
return 0;
}