题目传送门

Greatest Common Increasing Subsequence

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 10279    Accepted Submission(s): 3311

Problem Description
This is a problem from ZOJ 2432.To make it easyer,you just need output the length of the subsequence.
 
Input
Each sequence is described with M - its length (1 <= M <= 500) and M integer numbers Ai (-2^31 <= Ai < 2^31) - the sequence itself.
 
Output
output print L - the length of the greatest common increasing subsequence of both sequences.
 
Sample Input
1

5
1 4 2 5 -12
4
-12 1 2 4

 
Sample Output
2
 
Source
 
Recommend
lcy   |   We have carefully selected several similar problems for you:  1422 1421 1400 1418 1424 
题意:求两个序列的最长公共上升子序列
题解:定义dp[j]表示a序列中从1到n与b序列中从1到j并以b[j]为结尾的最长公共上升子序列的长度。
状态转移方程:dp[j] = dp[k] + 1, if(a[i] = = b[j]), 1 <= k < j.
代码:
#include<iostream>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<queue>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int,int> PII;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
//head
#define MAX 505
int T;
int n,m;
int a[MAX],b[MAX];
int dp[MAX];
void LCIS()
{
memset(dp,,sizeof(dp));
for(int i=;i<=n;i++)
{
int pos=;
for(int j=;j<=m;j++){
if(a[i]>b[j]&&dp[j]+>dp[pos]) pos=j;
if(a[i]==b[j]) dp[j]=dp[pos]+;
}
}
}
void solve()
{
LCIS();
int maxn=;
for(int i=;i<=m;i++)
{
maxn=max(maxn,dp[i]);
}
printf("%d\n",maxn);
}
int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
}
scanf("%d",&m);
for(int i=;i<=m;i++)
scanf("%d",&b[i]);
solve();
}
return ;
}
 

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

  1. HDU-1423 最长公共上升子序列(LCIS)

    问题描述: 给定两个字符串x, y, 求它们公共子序列s, 满足si < sj ( 0 <= i < j < |s|).要求S的长度是所有条件序列中长度最长的. 做过最长公共子 ...

  2. HDU1423 最长公共上升子序列LCIS

    Problem Description This is a problem from ZOJ 2432.To make it easyer,you just need output the lengt ...

  3. 最长公共上升子序列(codevs 2185)

    题目描述 Description 熊大妈的奶牛在小沐沐的熏陶下开始研究信息题目.小沐沐先让奶牛研究了最长上升子序列,再让他们研究了最长公共子序列,现在又让他们要研究最长公共上升子序列了. 小沐沐说,对 ...

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

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

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

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

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

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

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

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

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

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

  9. codevs 2185 最长公共上升子序列

    题目链接: codevs 2185 最长公共上升子序列codevs 1408 最长公共子序列 题目描述 Description熊大妈的奶牛在小沐沐的熏陶下开始研究信息题目.小沐沐先让奶牛研究了最长上升 ...

随机推荐

  1. restTemplate工具类

    import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.sprin ...

  2. 一、C++类库与C#类库相互调用

    1.C++调用C#类库 1.准备C#类库(dll文件) 1.1.创建C#类库: 右击项目类库生成即可, 出现.dll(类库)与.pdb(pdb文件包含了编译后程序指向源代码的位置信息, 用于调试的时候 ...

  3. Centos7搭建日志服务器rsyslog+loganalyzer

    一.系统环境 Rsyslog Server OS:CentOS 7 Rsyslog Server IP:172.28.194.118 Rsyslog Version: rsyslog-7.4.7-12 ...

  4. TCP窗口

    一.窗口移动1.在建立TCP连接时,接收端会告诉发送端自己的接收窗口.2.发送端在发送数据时,会先为数据分包,编号,然后先发送窗口大小的数据(数据大于窗口大小),小于则全部发送了,窗口后的不允许发送. ...

  5. tac反向显示文件内容

    1.命令功能 tac是cat的反向拼写功能是反向显示文件内容.cat是从文件第一行开始读取文件输出,tac是从最后一行开始读取文件并进行反向输出. 2.语法格式 tac  [option]  [fil ...

  6. hadoop中的一些术语介绍

    1.MR作业是客户端执行的一个工作单元:包括输入数据,MR的程序和配置信息. Hadoop将作业分成若干个任务task来执行,分为两种任务:map和reduce任务.这些任务运行在集群的节点上,并通过 ...

  7. Eclipse 创建springBoot项目的时候需要首先 安装STS(亲测)

    开始我的Eclipse版本是4.4.2.安装网上的步骤多次不成功. 后来直接去下载了最新版的Eclipse 2018-9版本的 是 4.9. 下面是安装步骤: (1)eclipse->Help- ...

  8. VS2017 IDE 说明

  9. Android 中的 Matrix

    Matrix 是 Android SDK 提供的一个矩阵类,它代表一个 3 X 3 的矩阵 Matrix主要可以对图像做4种基本变换 Translate 平移变换 Rotate 旋转变换 Scale ...

  10. sqlserver备份和恢复-5

    视图备份和恢复 备份 1. 2. 恢复 1. 2. 3.勾选覆盖现有数据库. 4. bat备份恢复 原文: https://www.cnblogs.com/lonelyxmas/p/7958649.h ...