The direct LCS is the time Complexity O (p*q), but the sequence elements are different, as long as one of the sequences is mapped into an orderly,
Another sequence that does the same mapping, without the direct deletion, becomes the one that asks for another sequence of Lis.
#include <bits/stdc++.h>using namespacestd;intRead () {CharC while(C=getchar (),c<'0'|| C>'9'); intRe = c'0'; while(C=getchar (), c>='0'&&c<='9') Re = re*Ten+c-'0'; returnre;}Const intMAXN = -* -;intMP[MAXN];intS[MAXN],G[MAXN];//#define LOCALintMain () {#ifdef LOCAL freopen ("In.txt","R", stdin);#endif intT scanf"%d",&T); for(intKS =1; KS <= T; ks++){ intN, p, q; scanf"%d%d%d",&n,&p,&q); Memset (MP,-1,sizeof(MP)); for(inti =0; I <= p; i++) {mp[read ()]=i; } intc =0; for(inti =0; I <= Q; i++){ intx =Mp[read ()]; if(~x) {S[c++] =x; }} memset (g,0x3f,sizeof(int) * (c+1)); intAns =0; for(inti =0; I < C; i++){ intK = Lower_bound (g+1, g+1+i,s[i])-G; G[K]=S[i]; Ans=Max (ans,k); } printf ("Case %d:%d\n", Ks,ans); } return 0;}
Uva 10635 Prince and Princess