hdu 1423
最长公共上升子序列: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的更多相关文章
- HDU 1423 Greatest Common Increasing Subsequence(最长公共上升LCIS)
HDU 1423 Greatest Common Increasing Subsequence(最长公共上升LCIS) http://acm.hdu.edu.cn/showproblem.php?pi ...
- HDU 1423 最长公共字串+上升子序列
http://acm.hdu.edu.cn/showproblem.php?pid=1423 在前一道题的基础上多了一次筛选 要选出一个最长的递增数列 lower_bound()函数很好用,二分搜索找 ...
- hdu 1423(LCS+LIS)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1423 好坑啊..还有公共串为0时的特殊判断,还有格式错误..看Discuss看知道除了最后一组测试数据 ...
- HDU 1423 LICS 模板
http://acm.hdu.edu.cn/showproblem.php?pid=1423 4.LICS.O(lena * lenb) 设dp[i][j]表示a[]的前i项,以b[]的第j项结尾时, ...
- HDU 1423 Greatest Common Increasing Subsequence
最长公共上升子序列 LCIS 看这个博客 http://www.cnblogs.com/nuoyan2010/archive/2012/10/17/2728289.html #include&l ...
- HDU 1423 Greatest Common Increasing Subsequence LCIS
题目链接: 题目 Greatest Common Increasing Subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: ...
- hdu 1423 最长公共递增子序列
这题一开始把我给坑了,我还没知道LCIS的算法,然后就慢慢搞吧,幸运的是还真写出来了,只不过麻烦了一点. 我是将该题转换为多条线段相交,然后找出最多多少条不相交,并且其数值死递增的. 代码如下: #i ...
- HDU 1423 Greatest Common Increasing Subsequence(LCIS)
Greatest Common Increasing Subsequenc Problem Description This is a problem from ZOJ 2432.To make it ...
- hdu 1423 最长上升递增子序列
#include <iostream> #include <cstdio> #include <cstring> using namespace std; ; in ...
随机推荐
- gcc的基础知识
GCC(GNU Compiler Collection,GNU编译器集合)是一套由GNU工程开发的支持多种编程语言的编译器. 基本用法 在使用Gcc编译器的时候,我们必须给出一系列必要的调用参数和文件 ...
- 2D几何
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #i ...
- XML前言
一.前言 1.XML全称"eXtensible Markup Language"(可扩展的标记语言) 2.DTD全称"Document Type Defintion&qu ...
- MySQL之select查询、function函数
一.select查询 //查询某张表所有数据 select * from temp; //查询指定列和条件的数据 //查询name和age这两列,age等于22的数据 ; //as对列重命名 //as ...
- ERwin 连接 mysql
1. install mysql connector; 2. run odbc connection management (c:\windows\syswow64\odbcad32.exe); 3. ...
- left join 改写标量子查询
数据库环境:SQL SERVER 2005 有一博彩的赔率是1:20,它有2张业务表:smuchs(投注表),lottery(开奖表). smuchs表有3个字段,分别是sno(投注号码).smuch ...
- 经历:Java中字符串中按照多个字符拆分或替换:split()和replaceAll()
一.replaceAll() 今天,遇到了这样的一个字符串[如下代码]: String s="@0|新港@0|天津@0|东莞@0|南沙@0|营口@0|钦州@0|上海@0|汕头@0|连云港@0 ...
- (十一)Hibernate 高级配置
第一节:配置数据库连接池 反问数据库,需要不断的创建和释放连接,假如访问量大的话,效率比较低级,服务器消耗大: 使用数据库连接池,我们可以根据实际项目的情况,定义连接池的连接个数,从而可以实现从连接池 ...
- DOM4j--write
import java.io.File; import java.io.FileNotFoundException;import java.io.FileOutputStream;import jav ...
- LIS
五:LIS 概念 最长上升子序列(Longest Increasing Subsequence,LIS),在计算机科学上是指一个序列中最长的单调递增的子序列.比如一个序列31 2 6 3 8,他的最长 ...