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