//
// main.cpp
// Richard
//
// Created by 邵金杰 on 16/9/27.
// Copyright © 2016年 邵金杰. All rights reserved.
//
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=500+10;
int a[maxn],b[maxn];
int dp[maxn];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,m;
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
scanf("%d",&m);
for(int i=1;i<=m;i++) scanf("%d",&b[i]);
memset(dp,0,sizeof(dp));
for(int i=1;i<=n;i++){
int ans=0;
for(int j=1;j<=m;j++){
if(a[i]>b[j]&&ans<dp[j]) ans=dp[j];
if(a[i]==b[j]) dp[j]=max(dp[j],ans+1);
}
}
int ans=0;
for(int i=1;i<=m;i++) ans=max(ans,dp[i]);
cout<<ans<<endl;
if(t) cout<<endl;
}
return 0;
}
HDU 1423 Greatest Common Increasing Subsequence(LCIS)
最新推荐文章于 2019-08-27 21:33:53 发布