最长公共上升子序列:O(n*m)的算法;

 #include<cstdio>
#include<cstring>
#define maxn 1000
using namespace std;
int a[maxn],b[maxn],f[maxn];
int main()
{
int t,n,m;
scanf("%d",&t);
while(t--)
{
memset(f,,sizeof f);
int ans=;
scanf("%d",&n);
for(int i=;i<n;i++)
scanf("%d",&a[i]);
scanf("%d",&m);
for(int i=;i<m;i++)
scanf("%d",&b[i]);
for(int i=;i<n;i++)
{
int k=;
for(int j=;j<m;j++)
{
if(a[i]==b[j])
if(f[j]<f[k]+)
f[j]=f[k]+;
if(a[i]>b[j])
if(f[k]<f[j])
k=j;
}
}
for(int i=;i<m;i++)
if(ans<f[i])ans=f[i];
printf("%d\n",ans);
if(t!=)printf("\n");
}
return ;
}

hdu 1423的更多相关文章

  1. HDU 1423 Greatest Common Increasing Subsequence(最长公共上升LCIS)

    HDU 1423 Greatest Common Increasing Subsequence(最长公共上升LCIS) http://acm.hdu.edu.cn/showproblem.php?pi ...

  2. HDU 1423 最长公共字串+上升子序列

    http://acm.hdu.edu.cn/showproblem.php?pid=1423 在前一道题的基础上多了一次筛选 要选出一个最长的递增数列 lower_bound()函数很好用,二分搜索找 ...

  3. hdu 1423(LCS+LIS)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1423 好坑啊..还有公共串为0时的特殊判断,还有格式错误..看Discuss看知道除了最后一组测试数据 ...

  4. HDU 1423 LICS 模板

    http://acm.hdu.edu.cn/showproblem.php?pid=1423 4.LICS.O(lena * lenb) 设dp[i][j]表示a[]的前i项,以b[]的第j项结尾时, ...

  5. HDU 1423 Greatest Common Increasing Subsequence

    最长公共上升子序列   LCIS 看这个博客  http://www.cnblogs.com/nuoyan2010/archive/2012/10/17/2728289.html #include&l ...

  6. HDU 1423 Greatest Common Increasing Subsequence LCIS

    题目链接: 题目 Greatest Common Increasing Subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: ...

  7. hdu 1423 最长公共递增子序列

    这题一开始把我给坑了,我还没知道LCIS的算法,然后就慢慢搞吧,幸运的是还真写出来了,只不过麻烦了一点. 我是将该题转换为多条线段相交,然后找出最多多少条不相交,并且其数值死递增的. 代码如下: #i ...

  8. HDU 1423 Greatest Common Increasing Subsequence(LCIS)

    Greatest Common Increasing Subsequenc Problem Description This is a problem from ZOJ 2432.To make it ...

  9. hdu 1423 最长上升递增子序列

    #include <iostream> #include <cstdio> #include <cstring> using namespace std; ; in ...

随机推荐

  1. 在安卓下使用python连接蓝牙串口模块(HC-06)

    在安卓上安装Python: 请参考:https://github.com/kuri65536/python-for-android/blob/master/README.md下载程序文件需要访问 ht ...

  2. 中国地图投影(实现Lambert投影)

    一.简介 目前Web地图已经是一个非常普遍的应用,百度地图,高德地图等等极大的方便了我们的生活和学习.本项目主要是在Web完成一个简单的中国地图的绘制,实现Lambert投影. 二.制图源数据信息及来 ...

  3. php的传值和传址

    有些情况下,可能希望在函数体内对参数的修改在函数体外也能反映; 使用引用传递参数要在参数前加上&符号; 例子: <?php $a=5; function show(&$a){   ...

  4. Java简单算法--求100以内素数

    package cn.magicdu.algorithm; /** * 打印素数 * * @author xiaoduc * */ public class Prim { public static ...

  5. ubuntu系统安装flashplayer

    打开浏览器,输入adobe flashplayer 进入官方网站,下载Linux 32-bit, 简体中文, Firefox,下载.tar.gz包. 然后点击立即下载.下载之后找到解压该文件夹,找到 ...

  6. ###《High-level event recognition in unconstrained videos》

    Author: Yu-Gang Jiang, Shih-Fu Chang 事件检测的目标就是自动识别给定视频序列中的感兴趣事件.进行视频事件检测通常很困难,特别是在网络中非限制的视频.在非限制情况下, ...

  7. UIButton 按钮文字左对齐

    btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; btn.titleEdgeInsets = UIEd ...

  8. 处理不等高TableViewCell

    课题一:如何计算Cell高度 方案一:直接法(面向对象) 想知道妹纸爱你有多深?直接去问妹纸本人吧! 嗯!Cell也是一样的,想知道cell到底有多高?直接问Cell本人就好了.直接法,就是把数据布局 ...

  9. Express安装与调试

    Express 是基于Node.Js平台,快速.开放.极简的 web 开发框架. 1.安装 Express的安装通过cmd来进行,过程如下: 首先,先在本地建立一个项目文件夹,取名Nodejs. 然后 ...

  10. Java初始化理解与总结 转载

    Java的初始化可以分为两个部分: (a)类的初始化 (b)对象的创建 一.类的初始化 1.1 概念介绍: 一个类(class)要被使用必须经过装载,连接,初始化这样的过程. 在装载阶段,类装载器会把 ...