题目传送门

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. OCTAVE-CONFIG

    SYNOPSIS 总览 octave-config [--m-site-dir] [--oct-site-dir] [-v|--version] [-h|-?|--help] DESCRIPTION ...

  2. 如何启用Nginx的status功能,查看服务器状态信息?

    如何查看服务器状态信息? 我们可以通过安装Nginx的功能模块,并修改Nginx的主配置文件来实现. 1.编译安装时使用--with-http_stub_status_module开启状态页面模块 [ ...

  3. RMQ Topic

    原创转载请注明出处:https://www.cnblogs.com/agilestyle/p/11794927.html RMQ Topic Project Directory Maven Depen ...

  4. INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES

    [转] https://www.mobibrw.com/2016/3949 adb install 一个apk错误: INSTALL_FAILED_ALREADY_EXISTS 应用已存在,使用 ad ...

  5. 数据库(一):事务的特性与事务(在同一个 JVM 中)的传递

    参考文章 https://blog.csdn.net/shuaihj/article/details/14163713 https://blog.csdn.net/shfqbluestone/arti ...

  6. postman与soapui操作

    get和post请求的区别? get请求:直接在浏览器里直接调用就可以了,不用借助工具   向服务端获取数据的    数据是放在url里面 post请求:向服务端发送数据的     数据放在body里 ...

  7. 减轻Temporal AA 的 拖影问题(ghosting)

    Temporal AA 效率高,但是有拖影等问题,UE4中可以如下修改减轻拖影问题: 搜索到PostProcessTemporalAA.usf文件,打开,找到 #define AA_DYNAMIC_A ...

  8. CSS实现回到顶部图片hover后改变效果

    任何网站中回到顶部元素不可缺少,一般为了实现交互效果,都会在鼠标hover后元素样式有所改变.今天这个实例便是采用CSS中的transform知识实现. hover: <!DOCTYPE htm ...

  9. 10 Advanced Bing Search Tricks You Should Know

    Exclude Websites From Bing Search: wikipedia -wikipedia.org Excluding Keywords From Bing Search: fac ...

  10. python+selenium 滑动滚动条的操作

    工作中碰到一种情况就是,要定位的元素需要滚动条滑到下方后才可以显示出来. 这种情况下,就要先滑动滚动条,再定位元素. 那么滑动滚动条我以前记录了appium中的操作,那么,selenium中该如何操作 ...