dp(最长公共上升子序列)
作者:互联网
This is a problem from ZOJ 2432.To make it easyer,you just need output the length of the subsequence.
InputEach sequence is described with M - its length (1 <= M <= 500) and M integer numbers Ai (-2^31 <= Ai < 2^31) - the sequence itself.Outputoutput print L - the length of the greatest common increasing subsequence of both sequences.Sample Input
InputEach sequence is described with M - its length (1 <= M <= 500) and M integer numbers Ai (-2^31 <= Ai < 2^31) - the sequence itself.Outputoutput print L - the length of the greatest common increasing subsequence of both sequences.Sample Input
1 5 1 4 2 5 -12 4 -12 1 2 4Sample 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; }
标签:mas,int,1009,序列,include,最长,dp 来源: https://www.cnblogs.com/nonames/p/11237948.html