30pts求调

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

123asd45__ @ 2023-12-03 19:49:47

#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int n;
int a[100010],b[100010];
int f[100010];
int c[100010],d[100010];
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        c[i]=i;
    }
    for(int i=1;i<=n;i++){
        cin>>b[i];
        d[i]=a[b[i]];
    }
    /*for(int i=1;i<=n;i++){
        //cout<<c[i]<<" ";
    }
    //cout<<endl;
    for(int i=1;i<=n;i++){
        //cout<<d[i]<<" ";
    }*/
    int len=0;
    for(int i=1;i<=n;i++){
        if(d[i]>f[len]){
            f[++len]=d[i];
        }
        else{
            int p=lower_bound(f+1,f+len+1,d[i])-f;
            f[p]=d[i];
        }
    }
    cout<<len;

    return 0;
}

by wulinxi101 @ 2023-12-04 11:42:14

#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
int n, a[100010],b[100010], f[100010], id[100010], len = 0;
int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
        id[a[i]] = i;
    }
    for(int i = 1; i <= n; i++)
    {
        cin >> b[i];
        b[i]= id[b[i]];
    }
    for(int i=1;i<=n;i++)
    {
        if(b[i] > f[len])
        {
            f[++len]=b[i];
        }
        else
        {
            int p = lower_bound(f + 1, f + len + 1, b[i]) - f;
            f[p] = b[i];
        }
    }
    cout << len;
    return 0;
}

by wulinxi101 @ 2023-12-04 11:42:41

你看一下我的


|