fork(1) download
  1. #include <stdio.h>
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. class Vacation {
  7. public:
  8. int happiness(vector<vector<int>>& tasks, int n, int t) {
  9. if(n == 0) return 0;
  10.  
  11. vector<vector<int>> dp(n, vector<int>(t, 0));
  12.  
  13. for(int i = 0; i < t; ++i) {
  14. dp[0][i] = tasks[0][i];
  15. }
  16.  
  17. for(int i = 1; i < n; ++i) {
  18. for(int j = 0; j < t; ++j) {
  19. dp[i][j] = tasks[i][j] + maxHappiness(dp[i-1], j);
  20. }
  21. }
  22. return maxHappiness(dp[n-1], -1);
  23. }
  24.  
  25. private:
  26. int maxHappiness(vector<int>& happiness, int exclude_day) {
  27. int res = -1;
  28. for(int i = 0; i < happiness.size(); ++i) {
  29. if(i == exclude_day) continue;
  30. res = max(res, happiness[i]);
  31. }
  32. return res;
  33. }
  34. };
  35.  
  36.  
  37. int main() {
  38. int n; cin >> n;
  39. int t = 3;
  40. vector<vector<int>> tasks(n, vector<int>(t));
  41.  
  42. for(int i = 0; i < n; ++i) {
  43. for(int j = 0; j < t; ++j) {
  44. cin >> tasks[i][j];
  45. }
  46. }
  47.  
  48. Vacation* obj = new Vacation();
  49. cout << obj->happiness(tasks, n, t) << endl;
  50. return 0;
  51. }
Success #stdin #stdout 0.01s 5300KB
stdin
7
6 7 8
8 8 3
2 5 2
7 8 6
4 6 8
2 3 4
7 5 1
stdout
46