Educational Codeforces Round 17 D. Maximum path DP

题目链接http://codeforces.com/contest/762/problem/D

多多分析状态;这个很明了

#include<bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
#define ls i<<1
#define rs ls | 1
#define mid ((ll+rr)>>1)
#define pii pair<LL,int>
#define MP make_pair
typedef long long LL;
const long long INF = 1e18;
const double Pi = acos(-1.0);
const int N = 1e6+10, M = 2e6+10, mod = 1e9+7, inf = 2e9;

void update(LL &x,const LL &y) {
    if(x < y) x = y;
}
LL a[3][N],dp[5][N];
int n;
int main() {
    scanf("%d",&n);
    for(int i = 0; i < 3; ++i)
        for(int j = 1; j <= n; ++j) scanf("%I64d",&a[i][j]);
    for(int i = 0; i < 5; ++i)
        for(int j = 0; j <= n; ++j) dp[i][j] = -INF;
    dp[0][0] = 0;
    for(int i = 1; i <= n; ++i) {
        update(dp[0][i],dp[0][i-1]+a[0][i]);
        update(dp[0][i],dp[1][i-1]+a[0][i]+a[1][i]);
        update(dp[0][i],dp[2][i-1]+a[0][i]+a[1][i]+a[2][i]);
        update(dp[0][i],dp[4][i-1]+a[0][i]+a[1][i]+a[2][i]);

        update(dp[1][i],dp[1][i-1]+a[1][i]);
        update(dp[1][i],dp[0][i-1]+a[0][i]+a[1][i]);
        update(dp[1][i],dp[2][i-1]+a[1][i]+a[2][i]);

        update(dp[2][i],dp[2][i-1]+a[2][i]);
        update(dp[2][i],dp[1][i-1]+a[2][i]+a[1][i]);
        update(dp[2][i],dp[0][i-1]+a[0][i]+a[1][i]+a[2][i]);
        update(dp[2][i],dp[3][i-1]+a[0][i]+a[1][i]+a[2][i]);

        update(dp[3][i],dp[0][i-1]+a[0][i]+a[1][i]+a[2][i]);
        update(dp[4][i],dp[2][i-1]+a[0][i]+a[1][i]+a[2][i]);
    }
    printf("%I64d\n",dp[2][n]);
    return 0;
}

 

posted @ 2017-03-25 17:35  meekyan  阅读(207)  评论(0编辑  收藏  举报