最长公共上升子序列: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. mongodb学习相关网址

    1.MongoDB官网 https://www.mongodb.org 2.MongoDB教程 http://www.yiibai.com/mongodb 3.MongoDB教程http://www. ...

  2. 今天学习了无序列表和有序列表和使用HTML5创建表格

    ol建立有序列表,该列表可以用设置type="A/a" 其语法架构为 <ol> <li></li> <li></li> ...

  3. css3渐变、背景、倒影、变形

    一.背景切割background-clip 语法:background-clip:border-box | padding-box | content-box: border-box      超出b ...

  4. SonarQube(5.0.1) 环境的安装配置

    SonarQube 安装步骤 确定 JDK 和 MySQL 已经成功安装. 下载 SonarQube 及工具 SonarQube Runner,下载地址:http://www.sonarqube.or ...

  5. Memcached 工作原理

    http://hzp.iteye.com/blog/1872664 Memcached处理的原子是每一个(key,value)对(以下简称kv对),key会通过一个hash算法转化成hash-key, ...

  6. SQL 拼接多个字段的值&一个字段多条记录的拼接 [轉]

    例如student表: studentID studentName studentScore 01 Alice 90 02 Bill 95 03 Cindy 100 一.拼接多个字段的值 select ...

  7. 正则化—Java中Split函数的用法技巧_(转载修改)

    原文地址:http://www.cnblogs.com/liubiqu/archive/2008/08/14/1267867.html java.lang.string.split split 方法  ...

  8. 批量杀进程——xargs用途

    ps -ef|grep ora|grep “LOCAL=YES”|awk ‘{print $2}’|xargs –I {} kill -9 {} ps -ef|grep ora|grep “LOCAL ...

  9. Ext.Net学习笔记19:Ext.Net FormPanel 简单用法

    Ext.Net学习笔记19:Ext.Net FormPanel 简单用法 FormPanel是一个常用的控件,Ext.Net中的FormPanel控件同样具有非常丰富的功能,在接下来的笔记中我们将一起 ...

  10. selinux理解1-selinux介绍

    安全增强式Linux(SELinux, Security-Enhanced Linux)是一种强制访问控制(mandatory access control)的实现.它的作法是以最小权限原则(prin ...