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 ...
随机推荐
- linux 修改 rsyncd.conf 配置文件
[root@rsync-server-1 ~]# cat > /etc/rsyncd.conf << EOF #Rsync server #created by sunsky 00: ...
- 吉首大学2019年程序设计竞赛(重现赛)I 滑稽树上滑稽果 (莫队+逆元打表)
链接:https://ac.nowcoder.com/acm/contest/992/I来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒空间限制:C/C++ 32768K,其他语言65536K ...
- oracle汇编03
.long expression1, expression2, ..., expressionNThe .long directive generates a long integer (32-bit ...
- 【LeetCode】动态规划(下篇共39题)
[600] Non-negative Integers without Consecutive Ones [629] K Inverse Pairs Array [638] Shopping Offe ...
- [sql 注入] 注入类型
基于整型的注入: url:http://localhost/?id=12 拼接sql:$sql = "select * from user where id = {$_GET['id']}& ...
- Robomongo可视化命令
## 更新命令示例 db.getCollection('collection_name').update( {'_id':ObjectId('id string')}, {$set:{' ...
- ES集群health为yellow解决办法
原创转载请注明出处:https://www.cnblogs.com/agilestyle/p/11766147.html Logstash导入数据后,Cerebro显示集群health的状态为yell ...
- 19 如何在String和Byte[]对象之间进行转换?
- Leetcode_1278. Palindrome Partitioning III_[DP]
题目链接 You are given a string s containing lowercase letters and an integer k. You need to : First, ch ...
- toutiao url
https://it.snssdk.com/article/v2/tab_comments/?group_id=6485899113563947533&item_id=648589911356 ...