HDU 5904 - LCIS (BestCoder Round #87)
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)的更多相关文章
- hdu 5904 LCIS dp
LCIS Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem Des ...
- hdu 5636 搜索 BestCoder Round #74 (div.2)
Shortest Path Accepts: 40 Submissions: 610 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: ...
- BestCoder Round #87 1003 LCIS[序列DP]
LCIS Accepts: 109 Submissions: 775 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65 ...
- BestCoder Round #87 LCIS(dp)
LCIS 要用dp的思路想这题 [题目链接]LCIS [题目类型]dp &题意: 给定两个序列,求它们的最长公共递增子序列的长度, 并且这个子序列的值是连续的,比如(x,x+1,...,y−1 ...
- HDU 5903 - Square Distance [ DP ] ( BestCoder Round #87 1002 )
题意: 给一个字符串t ,求与这个序列刚好有m个位置字符不同的由两个相同的串拼接起来的字符串 s, 要求字典序最小的答案 分析: 把字符串折半,分成0 - n/2-1 和 n/2 - n-1 d ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- BestCoder Round #87 1002 Square Distance[DP 打印方案]
Square Distance Accepts: 73 Submissions: 598 Time Limit: 4000/2000 MS (Java/Others) Memory Limit ...
- HDU 5904 LCIS (最长公共上升序列)
传送门 Description Alex has two sequences a1,a2,...,an and b1,b2,...,bm. He wants find a longest common ...
- BestCoder Round #87 1001
GCD is Funny Accepts: 524 Submissions: 1147 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 655 ...
随机推荐
- hdu5391 Zball in Tina Town(威尔逊定理)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Zball in Tina Town Time Limit: 3000/1500 ...
- uva 10929 - You can say 11
#include <cstdio> using namespace std; ]; int main() { while(gets(in)) { ] == ] == ) break; ; ...
- Python新手学习基础之数据类型——变量
关于Python的变量是这样描述的: 变量是存储在内存里的一个值,通过变量名,我们可以访问到该变量的值. 上面这几行代码中,price,count和sum都是变量,Python是动态类型语言,变量是不 ...
- C语言初学 比较五个整数并输出最大值和最小值1
#include<stdio.h> #include<math.h> int max(int x,int y) { if(x>y) return x; else retu ...
- GO求平均值
package main import "fmt" func main(){ sum:=0.0 avg:=0.0 xs:=" switch len(xs){ : avg= ...
- 运用Swagger 添加WebAPI 文档
1. Go to Web link https://www.nuget.org/packages/Swashbuckle/ and check which version do we want. 2. ...
- Google GFS文件系统深入分析
Google GFS文件系统深入分析 现在云计算渐成潮流,对大规模数据应用.可伸缩.高容错的分布式文件系统的需求日渐增长.Google根据自身的经验打造的这套针对大量廉价客户机的Google GFS文 ...
- javascript笔记3之数据类型
/* var box = 250; //十进制整型 alert(box); var box = 070; //八进制,按照十进制输出是56 alert(box); var box = 0x1f; // ...
- c语言结构体5之匿名结构体
注意: 1匿名结构体不会出现重合 重命名的情况 2有名结构体 名称不能相同 也就是不能重名 //匿名结构体不会出现重名的情况 struct //无名结构体 { ]; ]; int num; };//不 ...
- Annotation(二)——Hibernate中注解的开发
在利用注解开发数据库持久层以前,需要学习一个规范JPA(Java Persistence API),这也是SUN公司提出的数据库的持久化规范.就类似于JDBC,Servlet,JSP等规范一样.而Hi ...