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. 端口复用技术简单了解;重用端口;socket复用端口

    端口复用相关点 多个应用复用端口,只有最后一个绑定的socket可以接受数据,所有socket都可以发送数据 使用端口复用技术时,所有的socket都开启端口复用,才可以实现端口复用 黑客技术,使用标 ...

  2. Maven中<dependencies>节点和<dependencyManagement>节点的区别

    dependencyManagement只是插件管理,并不是真正的插件依赖,所以里面包含的插件在没有子项目使用的时候,并不会真正下载 1 .使用项目继承 利用项目继承可以将结构信息,部署信息,共同的依 ...

  3. CoreAudio实现录音播音和扬声器听筒模式的切换

    本例子使用Core Audio实现类似于微信的音频对讲功能,可以录音和播放并且实现了听筒模式和扬声器模式的切换.录音主要使用AVAudioRecorder类来实现录音功能,播放则使用AVAudioPl ...

  4. ubuntu14.04开启root用户 设置root密码 配置国内镜像源 设置分辨率

    一.Ubuntu 默认是不允许 root 通过 ssh 直接登录的,可以修改 /etc/ssh/sshd_config,设置 1 PermitRootLogin yes 然后重启 ssh 服务即可 1 ...

  5. Maximum Depth of Binary Tree leetcode java

    题目: Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the ...

  6. CSS文字换行详细解说

    本文列举了兼容 IE 和 FF 地换行 CSS 推荐样式,详细介绍了word-wrap同word-break地区别.兼容 IE 和 FF 地换行 CSS 推荐样式: 最好地方式是 word-wrap: ...

  7. 基于Packet Tracer 组建智能公司局域网

    背景及要求                                                                                               ...

  8. 【HTML5】实现QQ聊天气泡效果

    今天自己用 HTML/CSS 做了个类似QQ的聊天气泡,以下是效果图: 以下说下关键地方的样式设置.然后贴出html和css代码(不多). 步骤1:布局 消息採用div+float布局,每条消息用一个 ...

  9. QR分解与最小二乘

    主要内容: 1.QR分解定义 2.QR分解求法 3.QR分解与最小二乘 4.Matlab实现   一.QR分解 R分解法是三种将矩阵分解的方式之一.这种方式,把矩阵分解成一个正交矩阵与一个上三角矩阵的 ...

  10. C#.NET常见问题(FAQ)-如何给Listbox添加右键菜单

    1 拖一个ContextMenuStrip控件,然后可以直接在界面上编辑,也可以在FormLoad的时候动态添加   2 把这两个控件关联起来就可以实现listBox1的右键菜单跟ContextMen ...