Two Melodies CodeForces - 813D

Posted uid001

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Two Melodies CodeForces - 813D相关的知识,希望对你有一定的参考价值。

https://codeforces.com/problemset/problem/813/D  

DP好难啊.......

 

dp[i][j] = 一条链以i结尾, 另一条链以j结尾的最大值

关键要保证转移时两条链不能相交

 

 

#include <iostream>
#define REP(i,a,n) for(int i=a;i<=n;++i)
using namespace std;
const int N = 5e3+10, M = 1e7+10;
int n;
int a[N], dp[N][N], x[M], y[M];

int main() {
    cin>>n;
    REP(i,1,n) cin>>a[i];
    int ans = 0;
    REP(i,0,n) {
        REP(j,0,7) x[j]=0;
        REP(j,1,n) y[a[j]]=0;
        REP(j,1,i) { 
            x[a[j]%7]=max(x[a[j]%7],dp[i][j]);
            y[a[j]]=max(y[a[j]],dp[i][j]);
        }
        REP(j,i+1,n) {
            dp[i][j]=max(dp[i][0],max(y[a[j]+1],y[a[j]-1]));
            dp[i][j]=max(dp[i][j],x[a[j]%7]);
            dp[j][i]=++dp[i][j];
            x[a[j]%7]=max(x[a[j]%7],dp[i][j]);
            y[a[j]]=max(y[a[j]],dp[i][j]);
            ans = max(ans, dp[i][j]);
        }
    }
    printf("%d
", ans);
}

 

以上是关于Two Melodies CodeForces - 813D的主要内容,如果未能解决你的问题,请参考以下文章

codeforces:818G Four Melodies分析

Two Sets CodeForces - 468B

codeforces 620D D. Professor GukiZ and Two Arrays

Codeforces 845 C. Two TVs (模拟)

CodeForces 1073F Choosing Two Paths

CodeForces 550A Two Substrings(模拟)