hdoj problem 1423 Greatest Common Increasing Subsequence (动态规划)
来源:互联网 发布:2345软件大全官方网站 编辑:程序博客网 时间:2024/05/16 07:33
Greatest Common Increasing Subsequence
http://acm.hdu.edu.cn/showproblem.php?pid=1423
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4334 Accepted Submission(s): 1369
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
Source
ACM暑期集训队练习赛(二)
Recommend
lcy | We have carefully selected several similar problems for you: 1400 1418 1424 1401 1404
/*
题目大意是给定两个数字串a、b,求出它们最长公共递增子序列的长度。
状态dp[j]表示a中从0到n-1与b中从1到m-1并以b[j]为结尾的最长公共上升子序列的长度。
状态转移方程:dp[j] = dp[k] + 1,if (a[i] = b[j]&&1 <= k < j)
*/
题目大意是给定两个数字串a、b,求出它们最长公共递增子序列的长度。
状态dp[j]表示a中从0到n-1与b中从1到m-1并以b[j]为结尾的最长公共上升子序列的长度。
状态转移方程:dp[j] = dp[k] + 1,if (a[i] = b[j]&&1 <= k < j)
*/
/*
不明白为什么这种做法就WA求大神解释
WAWAWA
#include<cstdio>
#include<cstring>
#include<stdlib.h>
#include<algorithm>
using namespace std;
int dp[1010];
int a[510];
int b[510];
int Max(int a,int b)
{
return a>b?a:b;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n,i,j,k,sum=0,m;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
scanf("%d",&m);
for(i=0;i<m;i++)
scanf("%d",&b[i]);
memset(dp,0,sizeof(dp));
int len=0;
for(i=1;i<=n;i++)
{
dp[0]=0;
for(j=1;j<=i;j++)
{
if(a[i]>b[j])
dp[j]=Max(dp[j-1],dp[j]);
if(a[i]==b[j])
dp[j]=Max(dp[j-1],dp[j])+1;
}
}
for(i=1;i<=m;i++)
len=Max(dp[i],len);
printf("%d\n",len);
if(T)
printf("\n");
}
return 0;
}
*/
/*AC*/
#include<cstdio>
#include<cstring>
#include<stdlib.h>
#include<algorithm>
using namespace std;
int dp[1010];
int a[510];
int b[510];
int Max(int a,int b)
{
return a>b?a:b;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n,i,j,k,sum=0,m;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
scanf("%d",&m);
for(i=0;i<m;i++)
scanf("%d",&b[i]);
memset(dp,0,sizeof(dp));
int len=0,max=0;
for(i=0;i<n;i++)
{
max=0;
for(j=0;j<m;j++)
{
if(max<dp[j]&&a[i]>b[j])
max=dp[j];
if(a[i]==b[j])
dp[j]=max+1;
}
}
for(i=0;i<m;i++)
len=Max(dp[i],len);
printf("%d\n",len);
if(T)
printf("\n");
}
return 0;
}
0 0
- hdoj problem 1423 Greatest Common Increasing Subsequence (动态规划)
- HDOJ 1423 Greatest Common Increasing Subsequence -- 动态规划
- 动态规划-Greatest Common Increasing Subsequence
- POJ 2127 Greatest Common Increasing Subsequence (动态规划)
- POJ 2127 Greatest Common Increasing Subsequence -- 动态规划
- POJ:2127 Greatest Common Increasing Subsequence(动态规划)
- HDOJ 题目1423 Greatest Common Increasing Subsequence(LICS)
- zoj 2432 && hdoj 1423 Greatest Common Increasing Subsequence 【打印LCIS】
- HDU 1423 Greatest Common Increasing Subsequence(动态规划+最长公共上升子序列)
- 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
- 1423 Greatest Common Increasing Subsequence (LCIS)
- hdu 1423 Greatest Common Increasing Subsequence
- hdu 1423 Greatest Common Increasing Subsequence
- HDU 1423 Greatest Common Increasing Subsequence
- 转]Window, Linux动态链接库的分析对比
- 非递归实现斐波那契数列———修改版
- stactic function
- FreeRTOS(V8.0.1)系统之vTaskDelete()
- 解决VMware Tools没有自动启动的问题
- hdoj problem 1423 Greatest Common Increasing Subsequence (动态规划)
- avi文件格式解析
- 统计学习方法学习笔记:概论
- 视图控制器转场
- C/C++基本数据类型所占字节数
- iphone视频聊天代码实现
- 【二分图|最大匹配】POJ-1325 Machine Schedule
- objective-c中内存小结
- BOS_V6.3_BOS实施指南_单点登录(V2.0版)