Greatest Common Increasing Subsequence

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

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
 
 
代码:动态规划求最长增长公共序列 下面展示的是压缩空间的lcs,由于不需要记录顺序,所以这样写,较为简便,如果要记录路径只需要将lcs[]--->换成lcs[][],
然后maxc,变为lcs[][]的上一行即可!
 //增长lcs algorithm
#include<stdio.h>
#include<string.h>
#define maxn 505
int aa[maxn],bb[maxn];
int lcs[maxn];
int main()
{
int test,na,nb,i,j,maxc,res;
scanf("%d",&test);
while(test--)
{
scanf("%d",&na);
for(i=;i<=na;i++)
scanf("%d",aa+i);
scanf("%d",&nb);
for(j=;j<=nb;j++)
scanf("%d",bb+j);
memset(lcs,,sizeof(lcs));
for(i=;i<=na;i++)
{
maxc=;
for(j=;j<=nb;j++)
{
if(aa[i]==bb[j]&&lcs[j]<maxc+)
lcs[j]=maxc+;
if(aa[i]>bb[j]&&maxc<lcs[j])
maxc=lcs[j];
}
}
res=;
for(i=;i<=nb;i++)
if(res<lcs[i])res=lcs[i];
printf("%d\n",res);
if(test) putchar();
}
return ;
}

HDUOJ ---1423 Greatest Common Increasing Subsequence(LCS)的更多相关文章

  1. HDU 1423 Greatest Common Increasing Subsequence(LCIS)

    Greatest Common Increasing Subsequenc Problem Description This is a problem from ZOJ 2432.To make it ...

  2. 1423 Greatest Common Increasing Subsequence (LCIS)

    讲解摘自百度; 最长公共上升子序列(LCIS)的O(n^2)算法? 预备知识:动态规划的基本思想,LCS,LIS.? 问题:字符串a,字符串b,求a和b的LCIS(最长公共上升子序列).? 首先我们可 ...

  3. HDU 1423 Greatest Common Increasing Subsequence(最长公共上升LCIS)

    HDU 1423 Greatest Common Increasing Subsequence(最长公共上升LCIS) http://acm.hdu.edu.cn/showproblem.php?pi ...

  4. HDOJ 1423 Greatest Common Increasing Subsequence 【DP】【最长公共上升子序列】

    HDOJ 1423 Greatest Common Increasing Subsequence [DP][最长公共上升子序列] Time Limit: 2000/1000 MS (Java/Othe ...

  5. POJ 1423 Greatest Common Increasing Subsequence【裸LCIS】

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=1423 http://acm.hust.edu.cn/vjudge/contest/view.action ...

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

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

  7. HDU 1423 Greatest Common Increasing Subsequence LCIS

    题目链接: 题目 Greatest Common Increasing Subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: ...

  8. HDOJ 1423 Greatest Common Increasing Subsequence -- 动态规划

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1423 Problem Description This is a problem from ZOJ 2 ...

  9. HDU 1423 Greatest Common Increasing Subsequence(LICS入门,只要求出最长数)

    Greatest Common Increasing Subsequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536 ...

随机推荐

  1. Android图片加载框架最全解析(三),深入探究Glide的缓存机制

    在本系列的上一篇文章中,我带着大家一起阅读了一遍Glide的源码,初步了解了这个强大的图片加载框架的基本执行流程. 不过,上一篇文章只能说是比较粗略地阅读了Glide整个执行流程方面的源码,搞明白了G ...

  2. 1、cocos2d-x环境安装

     1 所需软件 2 安装python-2.7.8.amd64.msi 注意将当中的有一步设置,Add python.exe to path 设置python的环境变量 3 解压cocos2d-x- ...

  3. Python编程学习,高效求解素数程序实例

    素数是编程中经常需要用到的. 作为学习Python的示例,下面是一个高效求解一个范围内的素数的程序,不需要使用除法或者求模运算. #coding:utf-8 #设置python文件的编码为utf-8, ...

  4. 【计算机网络】详解网络层(二)ARP和RARP

    ARP ARP(Address Resolution Protocol,地址解析协议)是将IP地址解析为以太网MAC地址(物理地址)的协议.在局域网中,当主机或其他网络设备有数据要发送给另一个主机或设 ...

  5. c#递归生成XML

    递归方法大家应该都很熟悉了,简而言之就是方法内部调用自己,就这样不断重复重复再重复的执行, 不过要担心死循环哟... 当我们系统需要动态生成菜单时,也就是说我们系统的菜单是存在数据库中的,数据库结构类 ...

  6. eclipse全屏模式

  7. perl install-module.pl DateTime 执行无效问题的解决

    运行./checksetup.pl,总说DateTime模块需要安装,但是执行提示的perl install-module.pl DateTime 多次也还是说DateTime模块需要安装. 在神奇的 ...

  8. Discuz常见小问题-如何使用QQ登陆

    在首页中找到超链接 往下翻找到QQ互联,注意如果是内网无法开通(需要网站上传之后)

  9. Office WORD如何设置表格背景颜色

    1 点击表格-表格属性,边框和底纹. 2 选择应用于段落,这样只会应用于问题,效果不好. 3 选择应用于单元格可以避免上面的问题.

  10. Codeforces#86D Powerful array(分块暴力)

    Description An array of positive integers a1, a2, ..., an is given. Let us consider its arbitrary su ...