Jzoj4721 LCS

给你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);
}

posted @ 2017-10-15 16:37  扩展的灰(Extended_Ash)  阅读(113)  评论(0编辑  收藏  举报