题目地址: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. zoj 3820 Building Fire Stations 树的中心

    Building Fire Stations Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.zju.edu.cn/onlinejudge ...

  2. 第二周:01 ICP迭代交互

    本周主要任务01:利用PCL库函数,ICP融合两个角度的点云 任务时间:2014年9月8日-2014年9月14日 任务完成情况:可以使用键盘交互,显示每次ICP迭代结果 任务涉及基本方法: 1.PCL ...

  3. skip-character-set-client-handshake 与 character-set-client-handshake

    my.cnf [mysql] default-character-set = gbk [mysqld] skip-character-set-client-handshake=1 跳过mysql程序起 ...

  4. 在饼图上显示百分比值(报表生成器和 SSRS)

    在饼图上显示百分比值(报表生成器和 SSRS) 默认情况下,图例中显示了类别来标识每个值. 如果使用了类别标签标记饼图,则可能希望在图例中显示百分比. 注意 在 SQL Server Data Too ...

  5. 安装opencms时遇到问题及解决方法

    1. MySQL system variable 'max_allowed_packet' http://blog.csdn.net/hqa_ii/article/details/6872367 安装 ...

  6. MySQL(9):数据表的约束(列的属性)

    1.首先我们看一下这个图: 1.NULL| not NULL是否为空      规定一个字段的值是否为NULL 2.Default value 字段默认值属性 常见的是一个字段不能为空,而且存在默认值 ...

  7. php笔记03:布尔类型,字符串,浮点数

    1.布尔类型 下面情况都是看出false: 布尔类型FALSE自身 整型值为0 浮点型值为0.0 空字符串,以及字符串"0" 不包含任何元素的数组 不包含任何成员变量的对象(仅PH ...

  8. NAT技术基本原理与应用

    转载自:http://www.cnblogs.com/derrick/p/4052401.html?utm_source=tuicool&utm_medium=referral#undefin ...

  9. 如何使Android Studio项目发布到Jcenter中

    Android仓库 简单的普及下关于android的依赖仓库,有两种分别是Jcenter与Maven Central其实不管是Jcenter还是Maven Central都是Maven库. Jcent ...

  10. 给某个view增加颜色渐变图层

    //给某个view增加颜色透明度渐变图层 - (void) insertTransparentGradient { NSLog(@"%@",NSStringFromCGRect(s ...