Advertisement
Josif_tepe

Untitled

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