标签:
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
#include<bits/stdc++.h> using namespace std; #define ll long long #define pi (4*atan(1.0)) const int N=1e5+10,M=1e6+1010,inf=1e9+10,mod=1e9+7; const ll INF=1e18+10; int n,m; int a[N],b[N]; int dpn[M],dpm[M]; int main() { int T; scanf("%d",&T); while(T--) { int ans=0; scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) { scanf("%d",&a[i]); dpn[a[i]]=max(dpn[a[i]],dpn[a[i]-1]+1); } for(int i=1;i<=m;i++) { scanf("%d",&b[i]); dpm[b[i]]=max(dpm[b[i]],dpm[b[i]-1]+1); ans=max(ans,min(dpm[b[i]],dpn[b[i]])); } for(int i=1;i<=n;i++) dpn[a[i]]=0; for(int i=1;i<=m;i++) dpm[b[i]]=0; printf("%d\n",ans); } }
标签:
原文地址:http://www.cnblogs.com/jhz033/p/5905962.html