![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<stdio.h> 2 #include<string.h> 3 #include<algorithm> 4 using namespace std; 5 const int maxn = 205; 6 int a[ maxn ],b[ maxn ],dp[ maxn ]; 7 int s[ maxn ]; 8 int LCIS( int a[],int b[],int lena,int lenb ){ 9 /* 10 dp[i]:表示当b字符串到了第i个时,与a[]中的符合的最长公共上升子序列 11 */ 12 memset( dp,0,sizeof( dp ) ); 13 dp[ 0 ]=-1; 14 for( int i=1;i<=lena;i++ ){ 15 int locate = 0; 16 for( int j=1;j<=lenb;j++ ){ 17 if( a[i]>b[j]&&dp[ locate ]<dp[ j ] ){ 18 locate = j; 19 } 20 if( a[i]==b[j] ){ 21 dp[ j ]=dp[ locate ]>=0?(dp[ locate ]+1):1; 22 } 23 }//当a[i]时,遍历b中的dp最大的那个 24 } 25 int ans = 0; 26 for( int i = 1;i <= lenb; i++ ) 27 ans = max( ans,dp[ i ] ); 28 return ans; 29 } 30 31 int main(){ 32 int ca; 33 scanf("%d",&ca); 34 while( ca-- ){ 35 int n; 36 scanf("%d",&n); 37 for( int i=1;i<=n;i++ ) 38 scanf("%d",&a[ i ]); 39 int m; 40 scanf("%d",&m); 41 for( int i=1;i<=m;i++ ) 42 scanf("%d",&b[ i ]); 43 printf("%d\n",LCIS( a,b,n,m )); 44 if( ca ) printf("\n"); 45 } 46 return 0; 47 }