当前位置: 代码迷 >> 综合 >> UVA 10635 Prince and Princess LCS转化为LIS *
  详细解决方案

UVA 10635 Prince and Princess LCS转化为LIS *

热度:41   发布时间:2023-09-23 05:30:20.0

题目地址:http://vjudge.net/problem/UVA-10635

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int i=a;i<=(b);++i)
#define REPD(i,a,b) for(int i=a;i>=(b);--i)
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
const int maxn=250*250+5;
int r[maxn],a[maxn],d[maxn];
int binerySearch(int L,int R,int n){  //输出d[L~R]中小于等于n 的下标 while(L<=R){int mid=(L+R)>>1;if(d[mid]<n) L=mid+1;else R=mid-1;}return L;
}
int main(int argc, char const *argv[])
{int T,kase=0; scanf("%d",&T);while(T--){int n,p,q,x;scanf("%d%d%d",&n,&p,&q);memset(r,0,sizeof(r));REP(i,1,p+1) scanf("%d",&x),r[x]=i;REP(i,1,q+1) scanf("%d",&x),a[i]=r[x];d[1]=a[1];int len=1;REP(i,2,q+1){if(a[i]>d[len]) p=++len;else p=binerySearch(1,len,a[i]);d[p]=a[i];}printf("Case %d: %d\n", ++kase,len);}return 0;
}


  相关解决方案