Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- int n;
- int mat[100005][3];
- int memo[100005][3];
- int vacation(int i, int activity) {
- if(i == n) {
- return 0;
- }
- if(memo[i][activity] != -1) {
- return memo[i][activity];
- }
- int result = 0;
- for(int j = 0; j < 3; j++) {
- if(activity != j) {
- result = max(result, vacation(i + 1, j) + mat[i][activity]);
- }
- }
- return memo[i][activity] = result;
- }
- int main() {
- cin >> n;
- for(int i = 0; i < n; i++) {
- cin >> mat[i][0] >> mat[i][1] >> mat[i][2];
- memo[i][0] = memo[i][1] = memo[i][2] = -1;
- }
- cout << max(vacation(0, 0) , max(vacation(0, 1) , vacation(0, 2)) ) << endl;
- return 0;
- }
- // fib(7) = fib(6) + fib(5)
- //
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement