hdu 1423 Greatest Common Increasing Subsequence(不连续子序列)
来源:互联网 发布:ps软件有哪些 编辑:程序博客网 时间:2024/05/29 08:33
Greatest Common Increasing Subsequence
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4841 Accepted Submission(s): 1543
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
151 4 2 5 -124-12 1 2 4
Sample Output
2最长上升公共子序列,dp,,好好学学啊,唉2015,4,25,,下边是大神的解释 * DP(最长公共递增非连续子序列Greatest Common Increasing Subsequence) * 设数组f[i][j]代表第一个序列前i个数与第二个序列前j个数的 最长公共递增非连续子序列(GCIS) 的长度。 * 而数组tmp[i][j]则代表第一个序列前i个数与第二个序列前j个数的GCIS的最大数(即最后一个数) * max{f[i-1][j-1],f[i-1][j],f[i][j-1]} (当a[i]!=a[j]) * / * 状态转移方程:f[i][j]= * \ * max{f[i-1][j-1]+1(满足a[i]>tmp[i-1][j-1]), f[i-1][j-1],f[i-1][j]+1(满足a[i]>tmp[i-1][j]), f[i-1][j],f[i][j-1]+1(满足a[i]>tmp[i][j-1]),f[i][j-1]} (当a[i]==a[j]) */
#include<stdio.h>#include<string.h>#define M 550#define max(a,b) (a>b? a:b)int dp[M][M],a[M],b[M];int main(){int t,m1,m2,i,j,k;scanf("%d",&t);while(t--){scanf("%d",&m1);for(i=1;i<=m1;i++)scanf("%d",&a[i]);scanf("%d",&m2);for(i=1;i<=m2;i++)scanf("%d",&b[i]);memset(dp,0,sizeof(dp));for(i=1;i<=m1;i++){k=0;for(j=1;j<=m2;j++){dp[i][j]=dp[i-1][j];if(b[j]<a[i]&&k<dp[i-1][j])k=dp[i-1][j];if(b[j]==a[i])dp[i][j]=k+1;}}k=-1;for(i=1;i<=m2;i++)if(k<dp[m1][i])k=dp[m1][i];printf("%d\n",k);if(t!=0)printf("\n");}return 0;}
0 0
- hdu 1423 Greatest Common Increasing Subsequence(不连续子序列)
- HDU 1423 Greatest Common Increasing Subsequence(最长公共子序列+最长不下降子序列)
- hdu 1423 Greatest Common Increasing Subsequence (最长上升子序列)
- hdu 1423 Greatest Common Increasing Subsequence (最长上升子序列)
- HDU 1423 Greatest Common Increasing Subsequence(最长公共上升子序列)
- hdu 1423 Greatest Common Increasing Subsequence(最长公共上升子序列、LCIS)
- hdu 1423 Greatest Common Increasing Subsequence(最长公共递增子序列lcis)
- hdu 1423 Greatest Common Increasing Subsequence(最长公共上升子序列dp)
- HDU 1423 Greatest Common Increasing Subsequence(单调递增公共子序列)
- HDU 1423 Greatest Common Increasing Subsequence(动态规划+最长公共上升子序列)
- HDU 1423 Greatest Common Increasing Subsequence (最长公共上升子序列)【模板】
- 【最长公共子序列】杭电 HDU 1423 Greatest Common Increasing Subsequence
- hdu 1423 Greatest Common Increasing Subsequence 最长公共上升子序列
- hdu 1423 Greatest Common Increasing Subsequence(DP 最长公共上升子序列)
- hdu 1423 Greatest Common Increasing Subsequence(最长上升公共子序列)
- hdu 1423 Greatest Common Increasing Subsequence 最大公共上升子序列 DP
- HDU OJ 1423Greatest Common Increasing Subsequence 最长公共上升子序列
- HDU 1423(Greatest Common Increasing Subsequence)公共最长不降子序列
- Shell脚本基础介绍
- 输入两颗二叉树A,B,判断B是不是A的子结构。
- 哈希表基础知识(hash table)(1)
- 用java实现的一些插入(顺序和乱序)和查找(顺序和二分)
- SQL中的CASE WHEN用法:
- hdu 1423 Greatest Common Increasing Subsequence(不连续子序列)
- 黑马程序员——IO流(File对象)
- Marriage Match IV (hdu 3416 网络流+spfa最短路)
- 浅谈java常量池
- dede模版引擎工作原理和自定义标签
- WiFi-Display协议学习
- 《CTCI》2.1 移除未排序链表中的重复结点
- 计算string对象长度要使用strlen()和c_str()
- 安卓ColorStateList文件——文字的动作效果