Jzoj4721 LCS

来源:互联网 发布:java电脑版86 编辑:程序博客网 时间:2024/06/08 10:36

给你2个没有重复元素的序列A,B,求LCS

我们将映射A[i]->i用在B上,对B求LIS即可,若A中没有B[i]直接跳过

#include<stdio.h>#include<string.h>#include<algorithm>#include<map>using namespace std;map<int,int> s;int f[300010];int main(){int n,m; scanf("%d%d",&n,&m);for(int x,i=0;i<n;++i){scanf("%d",&x);s[x]=i+1;}memset(f,127,sizeof f);for(int x,i=0;i<m;++i){scanf("%d",&x);x=s[x];if(x) *lower_bound(f,f+m,x)=x;}printf("%d\n",lower_bound(f,f+m,0x7f7f7f7f)-f);}