Title Link: http://61.187.179.132/JudgeOnline/problem.php?id=1264
Test instructions: Give two series, each of the length of the series is 5n, wherein 1-n each number appears 5 times. The longest common child of two columns.
Idea: LCS turned into LIS, for each number that appears in the first array, turn it into the position in the second array, notice that the position is from the big to the small row, and then do the LIS for this array.
#include <algorithm>#include<cstdio>#include<cmath>#include<cstring>#include<iostream>intq[1000005],a[1000005],b[1000005],n,p[1000005],s[100005][6];intFindintx) { intL=1, r=q[0],ans; if(x<=q[1])return 0; while(l<=R) { intMid= (L+R)/2; if(q[mid]<x) ans=mid,l=mid+1; Elser=mid-1; } if(q[ans+1]<X)returnans+1; returnans;}intMain () {scanf ("%d",&N); for(intI=1; i<=5*n;i++) scanf ("%d",&A[i]); for(intj=1; j<=5*n;j++) scanf ("%d",&B[j]); for(intI=1; i<=5*n;i++){ for(intj=1; j<=5; j + +) if(s[b[i]][j]==0) {S[b[i]][j]=i; Break; } } for(intI=1; i<=5*n;i++){ intt=A[i]; for(intj=5; j>=1; j--) p[++p[0]]=S[t][j]; } q[0]=1; q[1]=p[1]; for(intI=2; i<=p[0];i++){ if(p[i]>q[q[0]]) q[++q[0]]=P[i]; Else{ intt=find (P[i]); Q[t+1]=P[i]; }} printf ("%d\n", q[0]); }
Bzoj 1264 Gene match match (LCS conversion lis)