POJ 1423 Greatest Common Increasing Subsequence【裸LCIS】
来源:互联网 发布:作图软件大全 编辑:程序博客网 时间:2024/06/07 19:35
链接:
http://acm.hdu.edu.cn/showproblem.php?pid=1423
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=28195#problem/F
Greatest Common Increasing Subsequence
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2757 Accepted Submission(s): 855
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
算法:
LCIS 【最长公共上升子序列分析】
code:
注意格式 问题:
#include<stdio.h>#include<string.h>#include<algorithm>#include<iostream>using namespace std;const int maxn = 500+50;int dp[maxn][maxn];int a[maxn],b[maxn];int m,n;/****求序列 A 长度为 N 和序列 B 长度为 M 的 LCS序列下标从 1 开始*/int LCS(){ for(int i = 1; i <= n; i++) { int tmp = 0; //记录在i确定,且a[i]>b[j]的时候dp[i,j]的最大值 for(int j = 1; j <= m; j++) { dp[i][j] = dp[i-1][j]; if(a[i] > b[j]) { tmp = dp[i-1][j]; } else if(a[i] == b[j]) dp[i][j] = tmp+1; } }//for(int i = 1; i <= m; i++) printf("%d ", dp[n][i]); printf("\n"); int ans = 0; for(int i = 1; i <= m; i++) ans = max(ans, dp[n][i]); return ans;}int main(){ int T; scanf("%d", &T); while(T--) { memset(dp,0,sizeof(dp)); scanf("%d", &n); for(int i = 1; i <= n; i++) scanf("%d", &a[i]); scanf("%d", &m); for(int j = 1; j <= m; j++) scanf("%d", &b[j]); printf("%d\n",LCS()); if(T != 0) printf("\n"); }}
内存优化:
#include<stdio.h>#include<string.h>#include<algorithm>#include<iostream>using namespace std;const int maxn = 500+50;int dp[maxn];int a[maxn],b[maxn];int m,n;/****求序列 A 长度为 N 和序列 B 长度为 M 的 LCS序列下标从 1 开始*/int LCS(){ for(int i = 1; i <= n; i++) { int tmp = 0; for(int j = 1; j <= m; j++) { if(a[i] > b[j] && dp[j] > tmp) { tmp = dp[j]; } else if(a[i] == b[j]) dp[j] = tmp+1; } } int ans = 0; for(int i = 1; i <= m; i++) ans = max(ans, dp[i]); return ans;}int main(){ int T; scanf("%d", &T); while(T--) { memset(dp,0,sizeof(dp)); scanf("%d", &n); for(int i = 1; i <= n; i++) scanf("%d", &a[i]); scanf("%d", &m); for(int j = 1; j <= m; j++) scanf("%d", &b[j]); printf("%d\n",LCS()); if(T != 0) printf("\n"); }}
- POJ 1423 Greatest Common Increasing Subsequence【裸LCIS】
- 1423 Greatest Common Increasing Subsequence (LCIS)
- HDU 1423--Greatest Common Increasing Subsequence【LCIS】
- HDU 1423 Greatest Common Increasing Subsequence(LCIS)
- HDU 1423 Greatest Common Increasing Subsequence (LCIS)
- POJ 2127 Greatest Common Increasing Subsequence(LCIS+输出路径)
- poj 2127 Greatest Common Increasing Subsequence (LCIS)
- POJ 2127 Greatest Common Increasing Subsequence(DP,LCIS)
- hdu 1423 Greatest Common Increasing Subsequence(LCIS)
- HDU 1423 Greatest Common Increasing Subsequence(最长公共上升LCIS)
- zoj 2432 && hdoj 1423 Greatest Common Increasing Subsequence 【打印LCIS】
- 【HDU 1423】Greatest Common Increasing Subsequence【LCIS 裸题】
- Greatest Common Increasing Subsequence(hdu1423(LCIS))
- HDU1423--Greatest Common Increasing Subsequence(LCIS)
- Greatest Common Increasing Subsequence poj-1423
- POJ 2127 Greatest Common Increasing Subsequence
- poj 2127 Greatest Common Increasing Subsequence
- poj 2127 Greatest Common Increasing Subsequence
- phpstorm的快捷键
- 常用正则表达式例子
- Grails2中的Many-to-many关系
- Cain嗅探到的RDP包批量解析为用户名+密码的php脚本
- Stratos2.0的架构
- POJ 1423 Greatest Common Increasing Subsequence【裸LCIS】
- 为什么优秀的程序员既懒又笨
- C# 仿金山毒霸启动和关闭淡入淡出效果
- anyevent::snmp+coro
- 细说Cookie
- C语言面试题目总结
- 实现在Hibernate中的分页查询原理解读
- SVN上传文件注意事项-------------------养成良好的项目文件上传习惯
- android 通过KSOAP调用.NET webservice中的服务接口