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 ...
随机推荐
- 基于 SwiftUI 创建一个可删除、可添加列表项的列表
执行环境 macOS Mojave: 10.14.5 xcode: Version 11.0 beta 6 (11M392q) 预览效果 完整代码 import SwiftUI class Item: ...
- Apache Mesos1.0.1 编译安装部署教程(ubuntu)
参考资料 官方文档:http://mesos.apache.org/documentation 中文翻译:http://mesos.mydoc.io/ GitHub:https://github.co ...
- JSP学习(1)
JSP学习(1) 什么是Web应用程序 可以Web访问呢的应用程序,用户只需要浏览器即可访问 静态网页与动态网页 静态网页:网页中内容固定 动态网页:内容通过程序动态显示,自动更新 Java Web应 ...
- 6-基于TMS320C6678、FPGA XC5VSX95T的6U CPCI 8路光纤信号处理卡
基于TMS320C6678.FPGA XC5VSX95T的6U CPCI 8路光纤信号处理卡 1.板卡概述 本板卡由我公司自主研发,基于CPCI架构,符合CPCI2.0标准,采用两片TI DSP T ...
- python基础--5字典
#字典#dict#基本结构info={ "k1":'v1' #键值对 ,"k2":"v2"} #字典的value可以是任何值# info={ ...
- python基础--4 元祖
#元组,元素不可被修改,不能被增加或者删除 #tuple,有序 tu=(11,22,33,44,55,33) #count 获取指定元素在元祖中出现的次数 print(tu.count(33)) #i ...
- 模块(os模块)
一.模块 一个python文件就是一个模块. 模块可分为: 1.标准模块:python自带的模块是标准模块,可以直接import进行使用的. eg:import json.import random. ...
- 2018-08-01-weekly
Algorithm 4. Median of Two Sorted Arrays What 两个排序数组的中位数 How 两个数组合并到同一个数组,然后进行排序取中间值即可 Key Codes cla ...
- Linux命令行工具之pidstat命令
原创转载请注明出处:https://www.cnblogs.com/agilestyle/p/11484624.html pidstat命令就可以帮助我们监测到具体线程的上下文切换 通过pidstat ...
- 19 如何在String和Byte[]对象之间进行转换?