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

本文介绍了一种求解两个不重复元素序列A和B的最长公共子序列(LCS)的方法,通过映射序列A的元素到其下标,并利用最长递增子序列(LIS)算法来高效解决该问题。
313

被折叠的 条评论
为什么被折叠?



