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\n\n", ans);
}
else
printf("%d\n" , ans); } return 0;
}
 
 

dp(最长公共上升子序列)的更多相关文章

  1. HDOJ 1423 Greatest Common Increasing Subsequence 【DP】【最长公共上升子序列】

    HDOJ 1423 Greatest Common Increasing Subsequence [DP][最长公共上升子序列] Time Limit: 2000/1000 MS (Java/Othe ...

  2. 【简单dp】poj 2127 Greatest Common Increasing Subsequence【最长公共上升子序列】【模板】

    Sample Input 5 1 4 2 5 -12 4 -12 1 2 4 Sample Output 2 1 4 题目:给你两个数字序列,求出这两个序列的最长公共上升子序列.输出最长的长度,并打表 ...

  3. LCIS 最长公共上升子序列问题DP算法及优化

    一. 知识简介 学习 LCIS 的预备知识: 动态规划基本思想, LCS, LIS 经典问题:给出有 n 个元素的数组 a[] , m 个元素的数组 b[] ,求出它们的最长上升公共子序列的长度. 例 ...

  4. 【线型DP模板】最上上升子序列(LIS),最长公共子序列(LCS),最长公共上升子序列(LCIS)

    BEGIN LIS: 一个数的序列bi,当b1 < b2 < … < bS的时候,我们称这个序列是上升的.对于给定的一个序列(a1, a2, …, aN),我们可以得到一些上升的子序 ...

  5. [CodeForces10D]LCIS(最长公共上升子序列) - DP

    Description 给定两个数列,求最长公共上升子序列,并输出其中一种方案. Input&Output Input 第一行一个整数n(0<n<=500),数列a的长度. 第二行 ...

  6. 最长公共上升子序列(LCIS)

    最长公共上升子序列慕名而知是两个字符串a,b的最长公共递增序列,不一定非得是连续的.刚开始看到的时候想的是先用求最长公共子序列,然后再从其中找到最长递增子序列,可是仔细想一想觉得这样有点不妥,然后从网 ...

  7. ZOJ 2432 Greatest Common Increasing Subsequence(最长公共上升子序列+路径打印)

    Greatest Common Increasing Subsequence 题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problem ...

  8. POJ 2127 最长公共上升子序列

    动态规划法: #include <iostream> #include <cstdio> #include <fstream> #include <algor ...

  9. 最长递增子序列(lis)最长公共子序列(lcs) 最长公共上升子序列(lics)

    lis: 复杂度nlgn #include<iostream> #include<cstdio> using namespace std; ],lis[],res=; int ...

随机推荐

  1. 2018-8-10-WPF-控件继承树

    title author date CreateTime categories WPF 控件继承树 lindexi 2018-08-10 19:16:53 +0800 2018-2-13 17:23: ...

  2. apache重写规则简单理解

    1.前提:开启apache重写,并把httpd.conf里的相关的AllowOverride denied改为AllowOverride all 2.重写规则可写在项目根目录的.htaccess文件或 ...

  3. bzoj4543 [POI2014]Hotel加强版 长链剖分+树形DP

    题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=4543 题解 这道题的弱化版 bzoj3522 [POI2014]Hotel 的做法有好几种吧. ...

  4. 关于Extjs获取容器和元素的方法

    1.当前对象的父对象(上级对象) this.ownerCt: 2.当前对象的下一个相邻的对象 this.nextSibling(); 3.当前对象的上一个相邻的对象 this.previousSibl ...

  5. 英国已有500万宽带用户接入并开始使用IPv6技术

    2018年英国首家为客户提供IPv6的主要ISP.随着所有现有的符合条件的用户线路启用,约90%的固定宽带用户群接入并开始使用IPv6,为IPv6互联网增加了超过500万个新眼球. 英国IPv6项目于 ...

  6. Ubuntu下批量使用Tecplot的preplot命令对数据进行处理

    首先把.PLT文件后缀批量修改为.dat rename 's/.PLT$/.dat/' *.PLT 对所有.dat文件批量执行preplot find ./ -name "*.dat&quo ...

  7. pip安装包出现timeout的解决办法

    今天安装django时老是出现timeout WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, sta ...

  8. Django2 --- cookie

    1. 什么是cookie ?用途是什么? Cookies是一些存储在用户电脑上的小文件.它是被设计用来保存一些站点的用户数据,这样能够让服务器为这样的用户定制内容,后者页面代码能够获取到Cookie值 ...

  9. rk3328编译Linux固件

    一.编译 Linux 固件 这一章将介绍编译 ROC-RK3328-CC Linux 固件的整个流程. 1.1 准备工作 Linux 固件在如下的环境中编译: Ubuntu 16.04 amd64 安 ...

  10. 基于ELK Stack7.1.0构建多用户安全认证日志系统

    ​ 配置tls加密通信及身份验证,主要目的是为了确保集群数据安全.在es早期版本,安全认证相关功能都属于商业付费服务,一般普通公司如果集群部署在内网,基本上就忽略了这些安全认证,当然也可以通过Ngin ...