hdu 1423 LICS

看了http://wenku.baidu.com/view/3e78f223aaea998fcc220ea0.html

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <queue>
 5 #include <algorithm>
 6 #include <cmath>
 7 #include <stack>
 8 #include <vector>
 9 #define LL long long
10 using namespace std;
11 const int inf=0x3f3f3f3f;
12 const int maxn=500+10;
13 int a[maxn],b[maxn],f[maxn];    
14 int main()
15 {
16     int T,n,m;
17     cin>>T;
18     while(T--)
19     {
20         int i,j;
21         cin>>n;
22         for(i=1;i<=n;i++) scanf("%d",&a[i]);
23         cin>>m;
24         for(i=1;i<=m;i++) scanf("%d",&b[i]);
25         int maxv;
26         memset(f,0,sizeof(f));
27         for(i=1;i<=n;i++)
28         {
29             maxv=0;
30             for(j=1;j<=m;j++)
31             {
32                 if(a[i]==b[j]) f[j]=maxv+1;
33                 if(a[i]>b[j]&&f[j]>maxv) maxv=f[j];
34             }
35         }
36         int ans=0;
37         for(i=1;i<=m;i++) if(f[i]>ans) ans=f[i];
38         printf("%d
",ans);
39         if(T) printf("
");
40     }
41     return 0;
42 }
原文地址:https://www.cnblogs.com/lj030/p/3236342.html