RE了5个点的动态规划解法,求助大犇

P1439 【模板】最长公共子序列

_ALIVE_LYY @ 2018-02-06 23:29:45

include<iostream>

using namespace std;

int a[1005],b[1005];

int f[1005][1005];

int main()

{

int n;
cin>>n;
for(int i=1;i<=n;i++){
    cin>>a[i];
}
for(int i=1;i<=n;i++){
    cin>>b[i];
}

f[0][0]=0;

for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){
        if(a[i]==b[j]){
            f[i][j]=f[i-1][j-1]+1;
        }
        else {
            f[i][j]=max(f[i][j-1],f[i-1][j]);
        }
    }
}
cout<<f[n][n];

}


by wucstdio @ 2018-03-18 15:24:15

你这是O(n^2)的做法,只能过1000以内的,当然RE了,要用nlogn的做法


by 做梦都想AK @ 2018-08-24 15:36:35

@wucstdio 话说大佬nlogn的做法咋写


by Clearlove7loveyou @ 2018-08-24 15:37:09

@qq770529510 +1


|