标签:you desc greatest set 子序列 scribe script style http
1
5
1 4 2 5 -12
4
-12 1 2 4
Sample Output
2
lis(最长上升子序列)和lcs(最长公共子序列)的结合lcis(最长公共上升子序列)还不是很懂这个问题
https://www.cnblogs.com/WArobot/p/7479431.html
#include <iostream>
#include <iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include <stdio.h>
#include <string.h>
using namespace std;
int w[109] , dp[1009] , a[1009] , b[1009];
int main()
{
int n ;
scanf("%d" , &n);
while(n--)
{
int m , l;
scanf("%d" , &m);
memset(dp , 0 , sizeof(dp));
for(int i = 1 ; i <= m ; i++)
{
scanf("%d" , &a[i]);
}
scanf("%d" , &l);
for(int i = 1 ; i <= l ; i++)
{
scanf("%d" , &b[i]) ;
}
int mas = 0 ;
for(int i = 1 ; i <= m ; i++)
{
mas = 0 ; // 记录b数组前j个与a数组前i个的最长公共升序列的个数
for(int j = 1 ; j <=l ; j++)
{
if(a[i] > b[j])
mas = max(mas , dp[j]);
if(a[i] == b[j])
dp[j] = mas + 1 ;
}
}
int ans = 0 ;
for(int i = 1 ; i <= l ; i++)
{
ans = max(ans , dp[i]);
}
if(n)
{
printf("%d\n\n", ans);
}
else
printf("%d\n" , ans);
}
return 0;
}
标签:you desc greatest set 子序列 scribe script style http
原文地址:https://www.cnblogs.com/nonames/p/11237948.html