Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <bits/stdc++.h>
- using namespace std;
- const int maxn = 1e5;
- int n;
- int a[4][maxn];
- int dp[4][maxn];
- int rec(int isk, int at){
- if(at == n){
- return 0;
- }
- if(dp[isk][at] != -1) {
- return dp[isk][at];
- }
- int rez = -1e8;
- for(int i = 1; i <= 3; i++){
- if(isk != i){
- rez = max(rez, rec(i, at + 1) + a[i][at]);
- }
- }
- return dp[isk][at] = rez;
- }
- int main()
- {
- cin >> n;
- for(int i = 0; i < n; i++){
- for(int j = 1; j <= 3; j++){
- cin >> a[j][i];
- }
- }
- memset(dp, -1, sizeof dp);
- cout << rec(0, 0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement