Advertisement
Josif_tepe

Untitled

Oct 31st, 2021
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. #include <iostream>
  2. #include <queue>
  3. using namespace std;
  4. int n;
  5. int mat[100005][3];
  6. int dp[100005][3];
  7. int main(){
  8.     cin >> n;
  9.     for(int i = 0; i < n; i++) {
  10.         cin >> mat[i][0] >> mat[i][1] >> mat[i][2];
  11.         dp[i][0] = dp[i][1] = dp[i][2] = -2e9;
  12.     }
  13.     dp[0][0] = mat[0][0];
  14.     dp[0][1] = mat[0][1];
  15.     dp[0][2] = mat[0][2];
  16.    
  17.     for(int day = 0; day + 1 < n; day++) {
  18.         for(int prev_activity = 0; prev_activity < 3; prev_activity++) {
  19.             for(int next_activity = 0; next_activity < 3; next_activity++) {
  20.                 if(prev_activity != next_activity) {
  21.                     dp[day + 1][next_activity] = max(dp[day + 1][next_activity], dp[day][prev_activity] + mat[day + 1][next_activity]);
  22.                 }
  23.             }
  24.         }
  25.     }
  26.     cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])) << endl;
  27.     return 0;
  28. }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement