-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlec10_15.cpp
67 lines (53 loc) Β· 1.59 KB
/
lec10_15.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//{ Driver Code Starts
#include <bits/stdc++.h>
using namespace std;
// } Driver Code Ends
class Solution {
public:
int maximumPoints(vector<vector<int>>& points) {
// Code here
int n = points.size();
vector<vector<int>> dp(n , vector<int>(4,0));
dp[0][0] = max(points[0][1],points[0][2]);
dp[0][1] = max(points[0][0] , points[0][2]);
dp[0][2] = max(points[0][0] , points[0 ][ 1]);
dp[0][3] = max (points[0][0] ,max(points[0][1], points[0][2]));
for(int day = 1 ; day<n; day++){
for(int last = 0 ; last <4;last++){
dp[day][last] = 0;
dp[day][last] = 0;
for(int task = 0 ; task<3; task++){
if(task!=last){
int point = points[day][task] + dp[day-1][task];
dp[day][last]= max(dp[day][last] ,point);
}
}
}
}
return dp[n-1][3];
}
};
//{ Driver Code Starts.
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<vector<int>> arr;
for (int i = 0; i < n; ++i) {
vector<int> temp;
for (int j = 0; j < 3; ++j) {
int x;
cin >> x;
temp.push_back(x);
}
arr.push_back(temp);
}
Solution obj;
cout << obj.maximumPoints(arr) << endl;
cout << "~" << endl;
}
return 0;
}
// } Driver Code Ends