HDU 1423 Greatest Common Increasing Subsequence

最长公共上升子序列   LCIS 看这个博客  http://www.cnblogs.com/nuoyan2010/archive/2012/10/17/2728289.html

 1 #include<iostream>
 2 #include<stdio.h>
 3 #include<algorithm>
 4 #include<cstring>
 5 #include<cmath>
 6 using namespace std;
 7 
 8 int num1[505],num2[505],dp[505][505];
 9 int main( )
10 {
11     int N,M,T; scanf("%d",&T);
12     while( T-- )
13     {
14         scanf("%d",&N);
15         for( int i = 1; i <= N; i++ )scanf("%d",&num1[i]);
16         scanf("%d",&M);
17         for( int i = 1; i <= M; i++ )scanf("%d",&num2[i]);
18         memset( dp,0,sizeof(dp) );
19         for( int i = 1; i <= N; i++ )
20         {
21             int Max = 0;
22             for( int j = 1; j <= M; j++ )
23             {
24                 if( num1[i] >  num2[j] && dp[i-1][j] > Max )Max = dp[i-1][j];
25                 if( num1[i] == num2[j] )
26                      dp[i][j] = Max + 1 ;
27                 else dp[i][j] = dp[i-1][j];
28             }
29         }
30         int res = 0;
31         for( int i = 1; i <= M; i++ )res = max( res,dp[N][i] );
32         cout<<res<<endl;
33         if( T )puts("");
34     }
35     return 0;
36 }
View Code

 

 

posted on 2013-10-06 17:27  浪舟  阅读(138)  评论(0编辑  收藏  举报

导航