poj 2127 Greatest Common Increasing Subsequence (记录路径LICS)
来源:互联网 发布:网络粪坑 编辑:程序博客网 时间:2024/05/20 17:24
题意:求最长递增公共子序列
这道题需要将该序列输出,这就牵涉到了路径记录的问题.
</pre><pre class="sio" name="code" style="white-space: pre-wrap; word-wrap: break-word; font-size: 14px; line-height: 26px; background-color: rgb(255, 255, 255);"><pre name="code" class="cpp">#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;int a[505],b[505],dp[505],n,m,cnt;int mark[505][505],ans[505];int LICS(){ int i,j,MAX,k; memset(dp,0,sizeof(dp)); memset(mark,0,sizeof(mark)); for(i = 1; i<=n; i++) { memcpy(mark[i],mark[i-1],sizeof(mark[0])); k = 0; for(j = 1; j<=m; j++) { if(a[i-1]>b[j-1] && dp[k]<dp[j]) k = j; if(a[i-1]==b[j-1] && dp[k]+1>dp[j]) { dp[j] = dp[k]+1; mark[i][j] = i*(m+1)+k;; } } } MAX = 0; for(i = 1; i<=m; i++) if(dp[MAX]<dp[i]) MAX = i; i = m*n+n+MAX; for(j = dp[MAX];j>0;j--) { ans[j-1] = b[i%(m+1)-1]; i = mark[i/(m+1)][i%(m+1)]; } return dp[MAX];}int main(){ int i,k; while(~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]); cnt = 0; k = LICS(); printf("%d\n",k); for(i = 0;i<k;i++) { if(i) printf(" "); printf("%d",ans[i]); } printf("\n"); } return 0;}
0 0
- poj 2127 Greatest Common Increasing Subsequence (记录路径LICS)
- POJ 题目2127 Greatest Common Increasing Subsequence(LICS,输出路径)
- 【poj 2127】Greatest Common Increasing Subsequence 最长公共上升子序列lics+路径打印
- poj2127 Greatest Common Increasing Subsequence(LICS+路径)
- HDU1423:Greatest Common Increasing Subsequence(LICS)
- POJ2127:Greatest Common Increasing Subsequence(LICS)
- HDU1423 Greatest Common Increasing Subsequence (LICS)
- POJ2127 Greatest Common Increasing Subsequence (LICS)
- 【poj 2127】Greatest Common Increasing Subsequence lics(输出答案坑死)
- POJ 2127 Greatest Common Increasing Subsequence(LCIS+输出路径)
- POJ 2127 Greatest Common Increasing Subsequence (最长公共上升子序列+记录路径)
- POJ 2127 Greatest Common Increasing Subsequence
- poj 2127 Greatest Common Increasing Subsequence
- poj 2127 Greatest Common Increasing Subsequence
- Greatest Common Increasing Subsequence poj 2127
- poj 2127 Greatest Common Increasing Subsequence
- POJ 2127 Greatest Common Increasing Subsequence
- POJ 2127 Greatest Common Increasing Subsequence
- Linux环境下OpenCv开发环境配置
- 在阿里云服务器上部署项目
- 汉诺塔题
- 为 Lua 绑定 C/C++ 对象
- javascript基础总结(一)--变量的作用域
- poj 2127 Greatest Common Increasing Subsequence (记录路径LICS)
- 第二章第2题
- java常用加密方式实现
- ExecutorService 多线程处理
- 类的知识点
- 【图像处理】使用CImage类将彩色图像转换成8位灰色图像
- 黑马程序员——Objective-C——内存管理
- J2SE多线程 part6 线程池概念
- iOS开发系列之常用框架开发集—自定义UINavigationController开发1