题目地址: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. 通过Wifi调试Android应用

    国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...

  2. webViewDidFinishLoad因为网页里的重定向,会调用多次,使用web view.isLoading来解决

    我编码如下,但我发现 webViewDidFinishLoad() 会发生若干次. 如何知道 webViewDidFinishLoad() 最后发生吗? iNavigate = ; - (void)w ...

  3. 使用Go语言两三事

    使用Go语言两三事,在网上看到的总结的很不错哦,转自http://www.cnblogs.com/sevenyuan/archive/2013/02/27/2935887.html 一.channel ...

  4. Sublime Text 2&3中输入法不跟随光标移动的问题的解决方法

    插件名称:IMESupport GitHub页面:https://github.com/chikatoike/IMESupport 安装方法: 手动安装和通过Package Control在线安装. ...

  5. Andorid4.x 流氓式屏蔽HOME键

    转载请列明出处 http://blog.csdn.net/steelychen/article/details/37757341 应用项目须要要屏蔽HOME键. 项目本身的要求是让按下HOME键后程序 ...

  6. web运维第一篇:nginx配置文件详解笔记

    #定义Nginx运行的用户和用户组 user www www; #nginx进程数,建议设置为等于CPU总核心数. worker_processes 8; #全局错误日志定义类型,[ debug | ...

  7. Oracle取得中文拼音首字母函数

    CREATE ) ; V_RETURN ) ; FUNCTION F_NLSSORT (P_WORD IN VARCHAR2) RETURN VARCHAR2 AS BEGIN RETURN NLSS ...

  8. 马上搞定Android平台的Wi-Fi Direct开发

    导语 移动互联网时代,很多用户趋向于将大量的资料保存在移动设备上.但在给用户带来便利的同时引发了一个新的问题——保存在移动设备上的资料该怎样共享出去?到了思考时间,普通青年这样想:折腾什么劲啊,直接用 ...

  9. PHP代码实现MySQL读写分离

    关于MySQL的读写分离有几种方法:中间件,Mysql驱动层,代码控制 关于中间件和Mysql驱动层实现Mysql读写分离的方法,今天暂不做研究, 这里主要写一点简单的代码来实现由PHP代码控制MyS ...

  10. nginx性能配置参数说明:

    nginx的配置:main配置段说明一.正常运行的必备配置: 1.user username [groupname]; 指定运行worker进程的用户和组 2.pid /path/to/pidfile ...