josiftepe

Untitled

Nov 14th, 2020
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.37 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4. const int maxn = 1e5 + 10;
  5. const int INF = 2e9 + 5;
  6. int n;
  7. int a[maxn][4];
  8. int happiness[maxn][4];
  9. int main(){
  10.     cin >> n;
  11.     for(int i = 0; i < n; ++i) {
  12.         cin >> a[i][0] >> a[i][1] >> a[i][2];
  13.         happiness[i][0] = happiness[i][1] = happiness[i][2] = -INF;
  14.     }
  15.     happiness[0][0] = a[0][0];
  16.     happiness[0][1] = a[0][1];
  17.     happiness[0][2] = a[0][2];
  18.     for(int day = 1; day < n; ++day) {
  19.         for(int prev_activity = 0; prev_activity < 3; ++prev_activity) {
  20.             for(int nxt_activity = 0; nxt_activity < 3; ++nxt_activity) {
  21.                 if(prev_activity == nxt_activity) {
  22.                     // ista aktivnost ne smee da se pravi vo 2 posledovatelni denovi
  23.                     continue;
  24.                 }
  25.                 happiness[day][nxt_activity] = max(happiness[day][nxt_activity], happiness[day - 1][prev_activity] + a[day][nxt_activity]);
  26.             }
  27.         }
  28.     }
  29. //    for(int i = 0; i < n; ++i) {
  30. //        cout << "Day " << i + 1 << ":\n";
  31. //        for(int j = 0; j < 3; ++j) {
  32. //            cout << "Activity: " << j + 1 << " " << happiness[i][j] << endl;
  33. //        }
  34. //        cout << endl;
  35. //    }
  36.     cout << max(max(happiness[n - 1][0], happiness[n - 1][1]), happiness[n - 1][2]) << endl;
  37.     return 0;
  38. }
  39. /*
  40.  3
  41.  10 20 30
  42.  30 40 1005
  43.  1  2  3
  44.  */
  45.  
Advertisement
Add Comment
Please, Sign In to add comment