#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <queue>
using namespace std;
int dp[550];
int T;
int a[550],b[550];
int main()
{
scanf("%d",&T);
int m,n;
while(T--)
{
scanf("%d",&m);
for(int i=1; i<=m; i++)
scanf("%d",&a[i]);
scanf("%d",&n);
for(int j=1; j<=n; j++)
scanf("%d",&b[j]);
memset(dp,0,sizeof(dp));
dp[0]=-1;
for(int i=1;i<=m;i++)
{
int locate =0;
for(int j=1;j<=n;j++)
{
if(a[i]>b[j]&&dp[j]>dp[locate]) locate = j;//在 b数组中找比a[i]小并且dp值最大的地方
if(a[i]==b[j])
{
if(locate==0)//如果在前j-1项没有找到比a[i]小的
dp[j]=1; //那么j的dp值就只能等于1
else dp[j] = dp[locate] +1;//否则就以比a[i]小的前面的数里dp值最大的数+1
}
}
}
int ans = -1;
for(int i =1;i<=n;i++)
{
if(ans<dp[i])
ans =dp[i];
}
printf("%d\n",ans);
if(T) printf("\n");
}
return 0;
}
分享到:
相关推荐
HDU2000至2099题的题目以及AC代码(含思路) 适合刚刚接触ACM的同学哦~ emmmm凑字
2019 Multi-University Training Contest 4(2019hdu多校第六场数据与标程)
有2019 Multi-University Training Contest 9,hdu多校第9场的题解,数据标程,有需要的可以下载哦
HDU上DP大集合,里面包括题,题解,代码,对DP入门者很实用,对DP老手也是有很大的提高
hdu 用C++编写的AC代码,大约200多题,里面有编号,部分题目有注释,有兴趣可以下来看下
13年3月30日多校第二场解题报告+标程
【HDU 3993】田忌赛马 题解+勘误 题解这里就略写一下了,主要是勘误。 这道题是2011年之前的多校训练题,2020年的今天,我们一个集训队全部挂在上面了。最后在HDU看到了9年前的讨论区,才知道这题有如下问题: speed...
HDU的1250,主要是利用高精度加法,但是代码有点繁琐,效率不是很高
HDU1059的代码
杭电ACMhdu1163
动态规划DP题解 POJ HDU部分动态规划DP题解
hdu1001解题报告
hdu 1574 passed sorce
HDU的一题........HDU DP动态规
自己做的HDU ACM已经AC的题目
Least Common Multiple Problem Description The least common multiple (LCM) of a set of positive integers is the smallest positive integer which is divisible by all the numbers in the set. For example, ...
hdu acm 教案 搜索入门 hdu acm 教案 搜索入门