
hdu1423---Greatest Common Increasing Subsequence(最长公共上升子序列)
发布日期:2022-02-02 02:58:12
浏览次数:4
分类:技术文章
本文共 1276 字,大约阅读时间需要 4 分钟。
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代码实现: #include#include using namespace std;int a[501],b[501];int dp[501][501];int main(){
int t,len1,len2,max;
cin>>t;
while(t--)
{
memset(dp,0,sizeof(dp));
cin>>len1;
for(int i=1; i<=len1; i++)
{
cin>>a[i];
}
cin>>len2;
for(int j=1; j<=len2; j++)
{
cin>>b[j];
}
for(int i=1; i<=len1; i++)
{
max=0;
for(int j=1; j<=len2; j++)
{
dp[i][j]=dp[i-1][j];
if(a[i]>b[j]&&max
{
max=dp[i-1][j];
}
if(a[i]==b[j])
{
dp[i][j]=max+1;
}
}
}
max=0;
for(int j=1; j<=len2; j++)
{
if(max
{
max=dp[len1][j];
}
}
cout<<
if(t)
{
cout<
}
}
return 0;}
转载地址:https://blog.csdn.net/u010368749/article/details/20448943 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
能坚持,总会有不一样的收获!
[***.249.68.14]2022年05月23日 04时20分59秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
最新文章
Python写xls笔记
2022-03-03
javascript学习笔记001
2022-03-03
Git批量删除文件
2022-03-03
python的二维数组操作
2022-03-03
Windows 8 系统环境下,Python3默认编码错误,导致运行文件失败的解决方法。
2022-03-03
oracle设置字母大小写不敏感对impdp无效
2022-03-03
Vue2全家桶搭建简单的桌面和移动端分离的购物商城
2022-03-03
俄罗斯方块小游戏的H5和Android版
2022-03-03
自制Influxdb可视化管理工具
2022-03-03
Vue开发踩坑及自救纪实
2022-03-03
MySQL实现Oracle的rank over(partition by...order by)叠加start with...connect by...prior...函数
2019-12-29 10:43:40
接口和抽象类之间的区别
2019-12-29 10:43:38
java的八大数据类型
2019-12-29 10:43:39
java中的List,Map,List<Map>
2019-12-29 10:43:39
类的加载生命周期
2019-12-29 10:43:39
用PyQt5开发桌面端数据库管理工具
2019-12-29 10:43:39
基于C++简易JSON解析器
2019-12-29 10:43:39
优化C++制作的简易密码管理工具
2019-12-29 10:43:39
转圈算法
2019-12-29 10:43:37
上班人员必读:“五险一金”详解!(转载)
2019-12-29 10:43:38