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\n\n", ans);
}
else
printf("%d\n" , ans); } return 0;
}
dp(最长公共上升子序列)的更多相关文章
- HDOJ 1423 Greatest Common Increasing Subsequence 【DP】【最长公共上升子序列】
HDOJ 1423 Greatest Common Increasing Subsequence [DP][最长公共上升子序列] Time Limit: 2000/1000 MS (Java/Othe ...
- 【简单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 题目:给你两个数字序列,求出这两个序列的最长公共上升子序列.输出最长的长度,并打表 ...
- LCIS 最长公共上升子序列问题DP算法及优化
一. 知识简介 学习 LCIS 的预备知识: 动态规划基本思想, LCS, LIS 经典问题:给出有 n 个元素的数组 a[] , m 个元素的数组 b[] ,求出它们的最长上升公共子序列的长度. 例 ...
- 【线型DP模板】最上上升子序列(LIS),最长公共子序列(LCS),最长公共上升子序列(LCIS)
BEGIN LIS: 一个数的序列bi,当b1 < b2 < … < bS的时候,我们称这个序列是上升的.对于给定的一个序列(a1, a2, …, aN),我们可以得到一些上升的子序 ...
- [CodeForces10D]LCIS(最长公共上升子序列) - DP
Description 给定两个数列,求最长公共上升子序列,并输出其中一种方案. Input&Output Input 第一行一个整数n(0<n<=500),数列a的长度. 第二行 ...
- 最长公共上升子序列(LCIS)
最长公共上升子序列慕名而知是两个字符串a,b的最长公共递增序列,不一定非得是连续的.刚开始看到的时候想的是先用求最长公共子序列,然后再从其中找到最长递增子序列,可是仔细想一想觉得这样有点不妥,然后从网 ...
- ZOJ 2432 Greatest Common Increasing Subsequence(最长公共上升子序列+路径打印)
Greatest Common Increasing Subsequence 题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problem ...
- POJ 2127 最长公共上升子序列
动态规划法: #include <iostream> #include <cstdio> #include <fstream> #include <algor ...
- 最长递增子序列(lis)最长公共子序列(lcs) 最长公共上升子序列(lics)
lis: 复杂度nlgn #include<iostream> #include<cstdio> using namespace std; ],lis[],res=; int ...
随机推荐
- javaScript基础--概念以及使用
1.什么javascript? 为什么要学习? 处理网站动态特效 为后期课程打基础 什么是javascript? 是一个客户端的具有安全性的脚本语言. js和h5 的关系 : 都是向静态的元素动起来 ...
- MongoDB的环境搭建及启动
MongoDB环境搭建及配置 一.环境搭建 Mac:brew install mongodb 常见问题: Error: Permission denied @ unlink_internal 解决方案 ...
- 外媒:Apple面临着印度iPhone的停用
据外媒报道:印度电信管理局(TRAI)制定遏制令人讨厌的消息的新规则可能导致印度数百万部iPhone的停用. 该监管机构本周早些时候宣布了“2018年电信商业通信客户偏好规定”,根据该规定,它已提议“ ...
- 对async 函数的研究
async 函数 1.ES2017 标准引入了 async 函数,使得异步操作变得更加方便. async 函数是什么?一句话,它就是 Generator 函数的语法糖. 前文有一个 Generator ...
- 用Jquery方法实现的简单下滑菜单效果
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- ueditor 复制word里面带图文的文章,图片可以直接显示
图片的复制无非有两种方法,一种是图片直接上传到服务器,另外一种转换成二进制流的base64码 目前限chrome浏览器使用,但是项目要求需要支持所有的浏览器,包括Windows和macOS系统.没有办 ...
- js中元素更新value页面体现不出来的原因
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- ASP.NET MVC3.0 标签提交
[HttpPost] [ValidateInput(false)] public ActionResult UpdateInformationData(ITMovingData p_data) { p ...
- [CSP-S模拟测试]:飞(fly)(数状数组+简单几何)
题目描述 $liu\_runda$决定提高一下知识水平,于是他去请教郭神.郭神随手就给了$liu\_runda$一道神题,$liu\_runda$并不会做,于是把这个题扔到联考里给高二的做.郭神有$n ...
- SQL利用Case When Then Else End 多条件判断
Select Case When a is not null then a When b is not null then b When c is not null then c When d is ...