Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define int long long
- const int mod = 1e9 + 7;
- const int N = 1e5 + 5;
- int n;
- int dp[N][5];
- int a[N];
- int b[N];
- int c[N];
- signed main()
- {
- cin >> n;
- for(int i = 1; i <= n; i++){
- cin >> a[i] >> b[i] >> c[i];
- }
- dp[1][1] = a[1];
- dp[1][2] = b[1];
- dp[1][3] = c[1];
- for(int i = 2; i <= n; i++){
- dp[i][1] = max(dp[i - 1][2] , dp[i - 1][3]) + a[i];
- dp[i][2] = max(dp[i - 1][1] , dp[i - 1][3]) + b[i];
- dp[i][3] = max(dp[i - 1][1] , dp[i - 1][2]) + c[i];
- //cout << dp[i][1] << " " << dp[i][2] << " " << dp[i][3] << endl;
- }
- cout << max(max(dp[n][1] , dp[n][2]) , dp[n][3]) << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement