Advertisement
LEGEND2004

Vacation

Aug 29th, 2023
1,107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define int long long
  5. const int mod = 1e9 + 7;
  6. const int N = 1e5 + 5;
  7. int n;
  8. int dp[N][5];
  9. int a[N];
  10. int b[N];
  11. int c[N];
  12.  
  13. signed main()
  14. {
  15.     cin >> n;
  16.     for(int i = 1; i <= n; i++){
  17.         cin >> a[i] >> b[i] >> c[i];
  18.     }
  19.     dp[1][1] = a[1];
  20.     dp[1][2] = b[1];
  21.     dp[1][3] = c[1];
  22.  
  23.     for(int i = 2; i <= n; i++){
  24.         dp[i][1] = max(dp[i - 1][2] , dp[i - 1][3]) + a[i];
  25.         dp[i][2] = max(dp[i - 1][1] , dp[i - 1][3]) + b[i];
  26.         dp[i][3] = max(dp[i - 1][1] , dp[i - 1][2]) + c[i];
  27.         //cout << dp[i][1] << " " << dp[i][2] << " " << dp[i][3] << endl;
  28.     }
  29.     cout << max(max(dp[n][1] , dp[n][2]) , dp[n][3]) << endl;
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement