最长公共上升子序列: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. 关于JSP异常的处理

    jsp中错误处理页面-isErrorPage="true" 举例说明:mustBeError.jsp <%@ page contentType="text/html ...

  2. Margin的垂直外边距问题

    做练习的时候遇到一个margin的问题,代码结构如下,给父元素body中的子元素div设置了margin:50px auto;本来我是想让子元素div距离父元素上边拉开50个像素,结果却是子元素div ...

  3. ASP大数据量使用GetRows()提升速度

    抽取10万条数据,Access数据库,GetRows() 现有10W条数据,Access数据库保存 通过正常提取: <% Set conn= Server.CreateObject(" ...

  4. spring mvc 全局异常处理

    package com.tool; public class MyException extends Exception{ public String Msg; public String ErrCo ...

  5. ubuntu 恢复gnome-panel

    Ubuntu重启panel 的方法首先进入终端, 依次输入以下命令1.gconftool --recursive-unset /apps/panel2.rm -rf ~/.gconf/apps/pan ...

  6. [PS] 透明底图片制作

    网页中有时需要自己绘制一些图片,或者现有的图片希望修改底色,这些都会用到透明底色的图片,下面总结两种方法,比较简单入门. 一.自己制作透明底图片 步骤1.新建图片,背景内容选择透明: 步骤2.选择文字 ...

  7. Mysql的联合查询

    联合查询 union联合查询 语法:     select 语句 union [all|distinct] select 语句; 示例: 特点:     条件:两表的查询出来的字段数目必须相同     ...

  8. 2.2_线性表的顺序存储结构_参考集合ArrayList

    [线性表的顺序存储从结构] 指的是用一段连续的存储单元一次储存线性表的数据元素. [线性表的顺序存储的结构代码 C语言版] #define MAXSIZE 20 /*存储空间初始分配量*/ typed ...

  9. JAVA日历

    效果图如下: import java.awt.*; import java.awt.event.*; import java.util.*; import javax.swing.*; import ...

  10. 九度OJ 1500 出操队形 -- 动态规划(最长上升子序列)

    题目地址:http://ac.jobdu.com/problem.php?pid=1500 题目描述: 在读高中的时候,每天早上学校都要组织全校的师生进行跑步来锻炼身体,每当出操令吹响时,大家就开始往 ...