Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #define ll long long
- #define vi vector<int>
- #define vii vector<ll>
- using namespace std;
- void file_io()
- {
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- }
- int main()
- {
- file_io();
- ll n;
- cin >> n;
- vector<vii> a(n, vii(3));
- for (ll i = 0; i < n; i++)
- {
- for (ll j = 0; j < 3; j++)
- {
- cin >> a[i][j];
- }
- }
- vii dp(n, -1);
- ll tmp = -1;
- dp[0] = max(a[0][0], max(a[0][1], a[0][2]));
- if (dp[0] == a[0][0])
- tmp = 0;
- else if (dp[0] == a[0][1])
- tmp = 1;
- else
- tmp = 2;
- for (ll i = 1; i < n; i++)
- {
- ll tmp2 = -1;
- for (ll j = 0; j < 3; j++)
- {
- if (tmp == j)
- continue;
- if (dp[i] < dp[i - 1] + a[i][j])
- {
- tmp2 = j;
- dp[i] = dp[i - 1] + a[i][j];
- }
- }
- tmp = tmp2;
- }
- cout << dp[n - 1] << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement