我随手打的lis...水过了???

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

单身贵族1123 @ 2018-11-02 21:28:34

好像最坏情况n^2

#include <cstdio>
#include <iostream>
#include <algorithm>

const int N=1e5;
using namespace std;

int n,p[N]={0},a[N]={0},f[N]={0},ans=1;

void fun(){
    f[1]=a[1];
    for(int i=2;i<=n;i++)
        if(f[ans]<a[i]) f[++ans]=a[i];
        else for(int j=1;j<=ans&&j<i;j++)
            if(f[j]>a[i]) {f[j]=a[i];break;}
    cout<<ans<<'\n';
}

int main()
{
    cin>>n;
    int tmp;
    for(int i=1;i<=n;i++) scanf("%d",&tmp) , p[tmp]=i;
    for(int i=1;i<=n;i++) scanf("%d",&tmp) , a[i]=p[tmp];
    fun();
}

by No268435 @ 2018-11-02 21:30:38

void fun()

???


by 引领天下 @ 2018-11-02 21:32:02

@单身贵族1123 orz


by NaCly_Fish @ 2018-11-02 21:36:29

orz


by 可比百分 @ 2018-11-02 21:38:59

我的一楼


by 可比百分 @ 2018-11-02 21:39:09

捧场


by 可比百分 @ 2018-11-02 21:39:26

zro orz


by 臣以为 @ 2018-11-02 21:40:08

%%%%%


by Eason_AC @ 2018-11-02 21:41:06

function的缩写,简称有趣(fun)


by 李尚儒 @ 2018-11-02 21:42:39

666


by NieR_Automata @ 2018-11-07 07:58:58

666


|