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. Sequential projection learning for hashing阅读笔记

    真不能再挖坑了,前面挖聊很多坑都没来得及填,从今往后,能写多少就是多少.Sequential projection learning for hashing这篇文章去年就阅读了,当时阅读完没来得及做笔 ...

  2. MyBatis+Spring SQL效率测试报告

    1. 数据库结构 2. insert 测试 insert 的测试包括 1) 批量拼接values()插入 2) 有事务for循环插入 3) 无事务for循环插入 测试 SQL: <!-- 普通 ...

  3. Redis中对Key进行分类

    使用":"体现层次 >set key1:key2:key4 value1 "OK" >set key1:key2:key5 value2 " ...

  4. 我所遭遇过的游戏中间件---nvDXTLib

    我所遭遇过的游戏中间件---nvDXTLib nvDXTLib是Nvidia提供的一套用于DXT纹理压缩SDK.接口十分简洁,就是提供了几个纹理压缩的函数,其中我使用最多的函数是: DXTLIB_AP ...

  5. SpringMVC in IDEA开发实践

    按照上篇装过Tomcat之后. 本机本来装了IDEA和Maven. 参考以下这篇 https://my.oschina.net/gaussik/blog/385697 <使用IntelliJ I ...

  6. HDU2669 Romantic 扩展欧几里德 对我来说有陷阱

    这道题对我来说有陷阱虽说是赤果果的扩展欧几里德,看样子基本攻还是不够哈,基本功夫一定要好,准备每天上那种洗脑课时分  多看看数论书,弥补一下 自己 狗一样的基础, 这道题用到了一个性质: 对于不定整数 ...

  7. iOS开发-Quartz2D初识

    Quartz2D如果单独的从Quartz,那么会发现Quartz是一个开源的Java作业调度框架,单独从英文翻译的角度来看的话Quartz的英文是石英,如果有的时候不小心搜索会发现手表推荐.本文中介绍 ...

  8. Java 解析Excel文件为JSON

    Excel转Json的需求 反正我对SSM基本不会的情况下来到现在这家公司,都是90后,感觉很好.第二天就给我开发任务,就是把用户上传的Excel文件转成JSON返回给前台用于大屏的数据展示. 解决方 ...

  9. 2015 HDU 多校联赛 5363 Key Set

    2015 HDU 多校联赛 5363 Key Set 题目: http://acm.hdu.edu.cn/showproblem.php? pid=5363 依据前面给出的样例,得出求解公式 fn = ...

  10. [Backbone] Parse not formatted JSON code

    The good Dr. recently had another team implement the server and they slightly messed up the format o ...