Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <queue>
- using namespace std;
- int n;
- int mat[100005][3];
- int dp[100005][3];
- int rec(int day, int prev_activity) {
- if(day == n) {
- return 0;
- }
- if(dp[day][prev_activity] != -1) {
- return dp[day][prev_activity];
- }
- int result = -2e9;
- for(int next_activity = 0; next_activity <= 2; next_activity++) {
- if(next_activity != prev_activity) {
- result = max(result, rec(day + 1, next_activity) + mat[day][prev_activity]);
- }
- }
- dp[day][prev_activity] = result;
- return result;
- }
- int main(){
- cin >> n;
- for(int i = 0; i < n; i++) {
- cin >> mat[i][0] >> mat[i][1] >> mat[i][2];
- dp[i][0] = dp[i][1] = dp[i][2] = -1;
- }
- int day1 = rec(0, 0);
- int day2 = rec(0, 1);
- int day3 = rec(0, 2);
- cout << max(day1, max(day2, day3)) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement