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
",lower_bound(f,f+m,0x7f7f7f7f)-f);
}

原文地址:https://www.cnblogs.com/Extended-Ash/p/9477305.html