dp(最长公共上升子序列)

https://vjudge.net/contest/313050#problem/C


lis(最长上升子序列)和lcs(最长公共子序列)的结合lcis(最长公共上升子序列)还不是很懂这个问题
https://www.cnblogs.com/WArobot/p/7479431.html

https://www.cnblogs.com/nuoyan2010/archive/2012/10/17/2728289.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

", ans);
        }
        else
            printf("%d
" , ans);


    }


    return 0;
}
 
 
原文地址:https://www.cnblogs.com/nonames/p/11237948.html