#include <iostream>
#define MAXN 501
using namespace std; int a[MAXN],b[MAXN],ans[MAXN]; int GCIS(int l1, int *a, int l2, int *b); int main()
{
//freopen("acm.acm","r",stdin);
int l_1;
int l_2;
int i;
int j;
int ans_max;
// cin>>l_1;
scanf("%d",&l_1); for(i = ; i < l_1; ++ i)
{
// cin>>a[i];
scanf("%d",&a[i]);
} // cin>>l_2;
scanf("%d",&l_2);
for(i = ; i < l_2; ++ i)
{
//cin>>b[i];
scanf("%d",&b[i]);
} cout<<(ans_max = GCIS(l_1,a,l_2,b) )<<endl; for(i = ; i < ans_max; ++ i)
{
cout<<ans[i]<<" ";
}
cout<<endl; } /////////////////////////////////////
//最长公共上升子序列~
/////////////////////////////////////
int GCIS(int l1, int *a, int l2, int *b)//ans[0...DP[max]-1]为序列,最长公共递增子序列!
{
int f[MAXN+][MAXN+];
int DP[MAXN+];
int i,j,k,max;
memset(f,,sizeof(f));
memset(DP,,sizeof(DP));
for (i=;i<=l1;i++)
{
k=;
for(int kk = ;kk <= l2;++ kk)
{
f[i][kk] = f[i-][kk];
}
for (j=;j<=l2;j++)
{
if(b[j-] < a[i-] && DP[j] > DP[k])
k=j;
if(b[j-]==a[i-]&&DP[k]+>DP[j])
{
DP[j]=DP[k]+;
f[i][j]=i*(l2+)+k;
}
}
}
max=;
for(i=;i<=l2;i++)
{
if (DP[i]>DP[max])
max=i;
}
i=l1*l2+l1+max;
for(j = DP[max];j > ;j --)
{
ans[j-] = b[i%(l2+)-];
i=f[i/(l2+)][i%(l2+)];
}
return DP[max];
}
///////////////////////////////////////////////////
//返回值是子序列的容量,容器为ans[]
///////////////////////////////////////////////////

关注我的公众号,当然,如果你对Java, Scala, Python等技术经验,以及编程日记,感兴趣的话。

技术网站地址: vmfor.com

POJ 2127的更多相关文章

  1. POJ 2127 Greatest Common Increasing Subsequence -- 动态规划

    题目地址:http://poj.org/problem?id=2127 Description You are given two sequences of integer numbers. Writ ...

  2. 【noi 2.6_2000】&【poj 2127】 最长公共子上升序列 (DP+打印路径)

    由于noi OJ上没有Special Judge,所以我是没有在这上面AC的.但是在POJ上A了. 题意如标题. 解法:f[i][j]表示a串前i个和b串前j个且包含b[j]的最长公共上升子序列长度 ...

  3. poj 2127 LCIS 带路径输出

    这个题   用一维 为什么错了: 因为 用一维 dp 方程肯定也是一维:但是有没有想,第 i 个字符更新了 j 位置的最优结果,然后 k 字符又一次更新了  j 位置的最优值,然后  我的结果是  i ...

  4. POJ 2127 最长公共上升子序列

    动态规划法: #include <iostream> #include <cstdio> #include <fstream> #include <algor ...

  5. POJ 2127 Greatest Common Increasing Subsequence

    You are given two sequences of integer numbers. Write a program to determine their common increasing ...

  6. 【简单dp】poj 2127 Greatest Common Increasing Subsequence【最长公共上升子序列】【模板】

    Sample Input 5 1 4 2 5 -12 4 -12 1 2 4 Sample Output 2 1 4 题目:给你两个数字序列,求出这两个序列的最长公共上升子序列.输出最长的长度,并打表 ...

  7. 最长公共上升子序列 (poj 2127) (Greatest Common Increasing Subsequence)

    \(Greatest Common Increasing Subsequence\) 大致题意:给出两个长度不一定相等的数列,求其中最长的公共的且单调递增的子序列(需要具体方案) \(solution ...

  8. ACM - 动态规划专题 题目整理

    CodeForces 429B  Working out 预处理出从四个顶点到某个位置的最大权值,再枚举相遇点,相遇的时候只有两种情况,取最优解即可. #include<iostream> ...

  9. LICS O(n*m)+前驱路径

    LICS:最长公共上升子序列: 一般令f[i][j]表示a串前i位,b串以j结尾的LICS长度.于是,答案为:max(1~m)(f[n][i]); 朴素做法:O(n^3) 相等时,从1~j-1枚举最大 ...

随机推荐

  1. .NET开源工作流RoadFlow-流程设计-流程步骤设置-基本设置

    流程属性设置完成后点击确定之后,即可进行流程步骤设置了. 点击工具栏上的步骤按钮,即可添加一个新步骤. 在新步骤图形上双击即可弹出该步骤相应属性设置框. 步骤ID:系统自动为该步骤生成的唯一ID. 步 ...

  2. node.js 在 Express4.0 框架使用 Connect-Busboy 实现文件上传

    node.js下四种post提交数据的方式 今天说分享的是其中一种,就是上传文件. Express 4.0 以后,将功能原子化,高内聚,低耦合,独立出了很多中间件 今天主要分享文件上传 对于conne ...

  3. 深入浅出const

    §通常,如果一个对象通过引用方式传到函数f中,而函数f又不会通过修改对象的数据成员的值改变该对象的状态,那么,我们最好将f的参数标记为const,这样可以预防对参数的误写,同时有些编译器还可对这种情况 ...

  4. hdu 4198 Quick out of the Harbour

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4198 Quick out of the Harbour Description Captain Cle ...

  5. Socket与TcpClient的区别(转载)

    Socket和TcpClient有什么区别 原文:http://wxwinter.spaces.live.com/blog/cns!C36588978AFC344A!322.entry 回答: &qu ...

  6. Android -- TouchEvent的分发和截获方式

    Android系统中的每个ViewGroup的子类都具有下面三个和TouchEvent处理密切相关的方法: public boolean dispatchTouchEvent(MotionEvent ...

  7. 【每日scrum】NO.1

    今天我们小组正式开始了冲刺,问题还是不少的,有必要记录下来来指导和改进后续的工作: 1.负责去找地图,却发现地图不能很好的适应我们的软件,略心塞>>> 2.本来计划把迪杰斯特拉算法看 ...

  8. nodejs笔记四--创建一个最简单的 express 应用

    express 是 Node.js 应用最广泛的 web 框架,利用 express 可以实现很多的web应用:首先需要需要得到一个express. 新建一个文件夹叫lesson1,进去里面安装 ex ...

  9. 18、ESC/POS指令集在android设备上使用实例(通过socket)

    网上关于通过android来操作打印机的例子太少了,为了方便更多的开发同仁,将近日所学分享一下. 我这边是通过android设备通过无线来对打印机(佳博58mm热敏式-58130iC)操作,实现餐厅小 ...

  10. 【Sort Colors】cpp

    题目: Given an array with n objects colored red, white or blue, sort them so that objects of the same ...