题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1423

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
 题目大意是给定两个数字串seq1、seq2,求出它们最长公共递增子序列的长度。
状态dp[j]表示seq1中从1到n与seq2中从1到j并以seq2[j]为结尾的最长公共上升子序列的长度。
状态转移方程:dp[j] = dp[k] + 1, if seq1[i] = seq2[j], 1 <= k < j.

#include <stdio.h>
#include <string.h> #define MAX 501 int T;
int seq1[MAX], seq2[MAX];
int len1, len2;
int dp[MAX]; int LCIS(){
int i, j;
int Max;
memset(dp, 0, sizeof(dp));
for (i = 1; i <= len1; ++i){
Max = 0;
for (j = 1; j <= len2; ++j){
if (seq1[i] > seq2[j] && Max < dp[j])
Max = dp[j];
if (seq1[i] == seq2[j])
dp[j] = Max + 1;
}
}
Max = 0;
for (i = 1; i <= len2; ++i){
if (Max < dp[i])
Max = dp[i];
}
return Max;
} int main(void){
int i;
scanf("%d", &T);
while (T-- != 0){
scanf("%d", &len1);
for (i = 1; i <= len1; ++i)
scanf("%d", &seq1[i]);
scanf("%d", &len2);
for (i = 1; i <= len2; ++i)
scanf("%d", &seq2[i]);
printf("%d\n", LCIS());
if (T)
putchar('\n');
} return 0;
}

HDOJ 1423 Greatest Common Increasing Subsequence -- 动态规划的更多相关文章

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

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

  2. HDOJ 1423 Greatest Common Increasing Subsequence(dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1423 思路分析:[问题定义]给定两个序列A[0, 1,..., m]和B[0, 1, ..., n], ...

  3. HDU 1423 Greatest Common Increasing Subsequence ——动态规划

    好久以前的坑了. 最长公共上升子序列. 没什么好说的,自己太菜了 #include <map> #include <cmath> #include <queue> ...

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

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

  5. HDUOJ ---1423 Greatest Common Increasing Subsequence(LCS)

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

  6. 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 ...

  7. HDU 1423 Greatest Common Increasing Subsequence LCIS

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

  8. POJ 2127 Greatest Common Increasing Subsequence -- 动态规划

    题目地址:http://poj.org/problem?id=2127 Description You are given two sequences of integer numbers. Writ ...

  9. HDU 1423 Greatest Common Increasing Subsequence(LCIS)

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

随机推荐

  1. Oracle 监听器无法启动(TNS-12555,TNS-12560,TNS-00525)

    启动监听器无法打开,报错! [oracle@localhost ~]$ lsnrctl start LSNRCTL for Linux: Version 11.2.0.1.0 - Production ...

  2. 封装的多功能多效果的RecyclerView

    开源界有一句很有名的话叫"不要重复发明轮子",当然,我今天的观点不是要反驳这句话,轮子理论给我们的开发带来了极大的便利,.但我想说的是,既要会用轮子,也要知道轮子怎么造,必要的时候 ...

  3. 实例:ABAP Tree Control 使用与ALV Grid对象关联

    Tree Control 是最常用的Windows控件之一,在其他语言中成为"Tree View"等,ABAP的 Tree Contiol 能实现类似的功能. 本文主要介绍一下内容 ...

  4. appDelegate中的委托协议方法以及使用观察者模式获取其触发方法

    //当应用程序将要进入非活动状态执行,在此期间,应用程序不接受消息或事件,比如来电 - (void)applicationWillResignActive:(UIApplication *)appli ...

  5. 基础数据结构 之 树(python实现)

    树是数据结构中常用到的一种结构,其实现较栈和队稍为复杂一些.若树中的所有节点的孩子节点数量不超过2个,则该为一个二叉树.二叉树可用于查找和排序等.二叉树的主要操作有:建树,遍历等.遍历是树中的一个最为 ...

  6. js中substr,substring,indexOf,lastIndexOf,split用法

    1.substr substr(start,length)表示从start位置开始,截取length长度的字符串. var src="images/off_1.png"; aler ...

  7. 从零开始学android开发-Json转换利器Gson之实例

    Gson 是 Google 提供的用来在 Java 对象和 JSON 数据之间进行映射的 Java 类库.可以将一个 JSON 字符串转成一个 Java 对象,或者反过来. jar和源码下载地址: h ...

  8. Matplotlib 工具包 使用教程索引

    官方文档链接中: http://matplotlib.org/gallery.html 这里给了非常多演示样例图片.能够查看对应源码,是一个非常好学习途径. matplotlib 函数API :函数A ...

  9. LeetCode144:Binary Tree Preorder Traversal

    Given a binary tree, return the preorder traversal of its nodes' values. For example: Given binary t ...

  10. 【剑指Offer学习】【面试题55:字符流中第一个不反复的字符】

    题目:请实现一个函数用来找出字符流中第一个仅仅出现一次的字符. 举例说明 比如,当从字符流中仅仅读出前两个字符"go"时.第一个仅仅出现一次的字符是'g'.当从该字符流中读出前六个 ...