HDU 5904 - LCIS [ DP ]    BestCoder Round #87

题意:

给定两个序列,求它们的最长公共递增子序列的长度, 并且这个子序列的值是连续的

分析:

状态转移方程式: dp[a[i]] = max(dp[a[i]], dp[a[i]-1] + 1);

发现其实可以简化为 dp[a[i]] = dp[a[i]-1] + 1;因为计算过程中dp[a[i]]不会降低

对两个序列都求一遍,然后取两者最小值的最大值

 #include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
using namespace std;
const int MAXM = ;
const int MAXN = ;
int t, n, m;
int a[MAXN], b[MAXN];
int dp1[MAXM], dp2[MAXM];
int main()
{
scanf("%d", &t);
while (t--)
{
scanf("%d%d", &n, &m);
memset(dp1, , sizeof(dp1));
memset(dp2, , sizeof(dp2));
int top = ;
for (int i = ; i <= n; i++)
{
scanf("%d", &a[i]);
dp1[a[i]] = dp1[a[i]-] + ;
top = max(top, a[i]);
}
for (int i = ; i <= m; i++)
{
scanf("%d", &b[i]);
dp2[b[i]] = dp2[b[i]-] + ;
top = max(top, b[i]);
}
int ans = ;
for (int i = ; i <= top; i++) ans = max(ans, min(dp1[i], dp2[i]));
printf("%d\n", ans);
}
}

HDU 5904 - LCIS (BestCoder Round #87)的更多相关文章

  1. hdu 5904 LCIS dp

    LCIS Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Des ...

  2. hdu 5636 搜索 BestCoder Round #74 (div.2)

    Shortest Path  Accepts: 40  Submissions: 610  Time Limit: 4000/2000 MS (Java/Others)  Memory Limit: ...

  3. BestCoder Round #87 1003 LCIS[序列DP]

    LCIS  Accepts: 109  Submissions: 775  Time Limit: 4000/2000 MS (Java/Others)  Memory Limit: 65536/65 ...

  4. BestCoder Round #87 LCIS(dp)

    LCIS 要用dp的思路想这题 [题目链接]LCIS [题目类型]dp &题意: 给定两个序列,求它们的最长公共递增子序列的长度, 并且这个子序列的值是连续的,比如(x,x+1,...,y−1 ...

  5. HDU 5903 - Square Distance [ DP ] ( BestCoder Round #87 1002 )

    题意: 给一个字符串t ,求与这个序列刚好有m个位置字符不同的由两个相同的串拼接起来的字符串 s, 要求字典序最小的答案    分析: 把字符串折半,分成0 - n/2-1 和 n/2 - n-1 d ...

  6. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  7. BestCoder Round #87 1002 Square Distance[DP 打印方案]

    Square Distance  Accepts: 73  Submissions: 598  Time Limit: 4000/2000 MS (Java/Others)  Memory Limit ...

  8. HDU 5904 LCIS (最长公共上升序列)

    传送门 Description Alex has two sequences a1,a2,...,an and b1,b2,...,bm. He wants find a longest common ...

  9. BestCoder Round #87 1001

    GCD is Funny Accepts: 524 Submissions: 1147 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 655 ...

随机推荐

  1. html的form元素

    <input type="email"><br> <input type="date"><br> <inp ...

  2. Hibernate插入数据效率测试

    硬件配置: 4G内存.CPUi3-2.3 数据库SQL2008 package com.pan.test; import org.hibernate.Session; import org.hiber ...

  3. 安装hadoop2.6.0伪分布式环境

    集群环境搭建请见:http://blog.csdn.net/jediael_lu/article/details/45145767 一.环境准备 1.安装linux.jdk 2.下载hadoop2.6 ...

  4. .net framework3.0 以上版本开发的软件乱码问题

    首先介绍一下:WPF是微软新一代图形系统,运行在.NET Framework 3.0及以上版本下,为用户界面.2D/3D 图形.文档和媒体提供了统一的描述和操作方法.基于DirectX 9/10技术的 ...

  5. Flask学习记录之Flask-Mail

    Flask-Mail可以连接到配置中的SMTP服务器,进行邮件发送,如果没有进行SMTP服务器的配置,将会默认连接到localhost上的 一.配置及初始化 (1)flask应用配置 #配置选项 MA ...

  6. 关于t分布的证明

  7. 关于一个小bug的修正

    python初学者,非常喜欢虫师的文章. 练习时发现一个小bug,http://www.cnblogs.com/fnng/p/3782515.html 验证邮箱格式一题中,第三个x不允许有数字,但是测 ...

  8. Ubuntu 12.04 更新源

    转载自:http://www.cnblogs.com/eastson/archive/2012/08/24/2654163.html 1.首先备份Ubuntu12.04源列表 sudo cp /etc ...

  9. Visual studio 内存不足的解决方案(out of memory)

    编译Visual Studio项目,如果出现"out of memory "的编译错误,可以进行如下操作,加大应用程序可以使用的内存. 请先备份好系统和设置好系统还原点,大体步骤是 ...

  10. code first 尝试

    建表: 1.先用EF连接数据库,配置connectionStrings <configSections> <!-- For more information on Entity Fr ...