暴力50分求助

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

Reobrok_Kk @ 2020-08-10 16:08:46

#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
using namespace std;
int a[5001],b[5001];
int f[5001][5001];
int max(int x,int y){return x>y?x:y;}
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];
    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;
        if(a[i]!=b[j]) f[i][j]=max(f[i][j-1],f[i-1][j]);
        }
    cout<<f[n][n]<<endl;
    return 0;
}

求dalao O(n log n) 解法思路


by 天有不测风云 @ 2020-08-10 16:10:17

你才学到完全背包啊…………


by 天有不测风云 @ 2020-08-10 16:12:36

emmmm


by X2H_tato @ 2020-08-10 16:18:45

@俺太难了 O(n*n)过不了啊


by X2H_tato @ 2020-08-10 16:19:22

写正解吧


by Reobrok_Kk @ 2020-08-10 16:19:27

求dalao O(n log n) 解法思路


by Reobrok_Kk @ 2020-08-10 16:22:17

@高高苦力怕 求正解思路


by X2H_tato @ 2020-08-10 16:22:21

@俺太难了 这个挺好的


by Reobrok_Kk @ 2020-08-10 16:24:32

@高高苦力怕 蟹蟹dalao

orz orz orz %%%


by Dovuq @ 2020-12-25 20:15:41

246810


by Miraii @ 2021-02-19 10:54:33

烤咕,orz已成为dalao的@neach_joup


| 下一页