hdu 1423 Greatest Common Increasing Subsequence

http://acm.hdu.edu.cn/showproblem.php?pid=1423

求最长公共递增子序列的长度。

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 #define maxn 1000
 5 using namespace std;
 6 
 7 int dp[maxn];
 8 int a[maxn],b[maxn];
 9 int t,n,m;
10 
11 int main()
12 {
13     scanf("%d",&t);
14     while(t--)
15     {
16         scanf("%d",&n);
17         for(int i=1; i<=n; i++)
18         {
19             scanf("%d",&a[i]);
20         }
21         scanf("%d",&m);
22         for(int j=1; j<=m; j++)
23         {
24             scanf("%d",&b[j]);
25         }
26         memset(dp,0,sizeof(dp));
27         for(int i=1; i<=n; i++)
28         {
29             int max1=0;
30             for(int j=1; j<=m; j++)
31             {
32                 if(a[i]>b[j]&&max1<dp[j])
33                     max1=dp[j];
34                 if(a[i]==b[j])
35                 {
36                     dp[j]=max1+1;
37                 }
38             }
39         }
40         int max2=-1;
41         for(int i=1; i<=m; i++)
42         {
43             max2=max(max2,dp[i]);
44         }
45         printf("%d
",max2);
46         if(t) printf("
");
47     }
48     return 0;
49 }
View Code
原文地址:https://www.cnblogs.com/fanminghui/p/3873426.html