BestCoder Round #87(1003-【思维】【LISLCS】)
题目链接:点击打开链接
1003-LCIS
The first line contains two integers n and m
(1≤n,m≤100000)
-- the length of two sequences. The second line contains n
integers: a
1
,a
2
,...,a
n
(1≤a
i
≤10
6
)
. The third line contains n
integers: b
1
,b
2
,...,b
m
(1≤b
i
≤10
6
)
.
There are at most 1000 test cases and the sum of n
and m
does not exceed 2×10
6
.
题解:
令f(i)f(i)是以a_ia i结尾的最大值, g(i)g(i)是以b_ibi结尾的最大值. 答案就是\max_{a_i = b_j} {\min(f(i),g(j)}maxai=bj{min(f(i),g(j)}. ff和gg随便dp一下就出来了.
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int MAXN=1e5+10;
int n,m;
int a[MAXN],b[MAXN];
int dp1[MAXN],dp2[MAXN];
int main()
{int t;scanf("%d",&t);while(t--){scanf("%d %d",&n,&m);for(int i=0;i<MAXN;i++) {a[i]=b[i]=dp1[i]=dp2[i]=0;}
// 这里用 for来初始化数组也可以,用 memset一般初始化一些较大的结构体和数组比较省时
// 像空间比较小的如 100,用 for就比较快
// memset(a,0,sizeof(a));
// memset(b,0,sizeof(b));
// memset(dp1,0,sizeof(dp1));
// memset(dp2,0,sizeof(dp2));for(int i=0;i<n;i++){scanf("%d",&a[i]);dp1[a[i]]=max(dp1[a[i]],dp1[a[i]-1]+1);}for(int i=0;i<m;i++){scanf("%d",&b[i]);dp2[b[i]]=max(dp2[b[i]],dp2[b[i]-1]+1);}int ans=0;for(int i=0;i<n;i++){ans=max(ans,min(dp1[a[i]],dp2[a[i]]));}
// for(int i=0;i<m;i++) 任意找一个(a或 b) dp都可以
// {
// ans=max(ans,min(dp1[b[i]],dp2[b[i]]));
// } printf("%d\n",ans);}return 0;
}
BestCoder Round #87(1003-【思维】【LISLCS】)相关推荐
- BestCoder Round #87 1003 LCIS[序列DP]
LCIS Accepts: 109 Submissions: 775 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65 ...
- BestCoder Round #29 1003 (hdu 5172) GTY's gay friends [线段树 判不同 预处理 好题]
传送门 GTY's gay friends Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Ot ...
- BestCoder Round #86 1003 HDU 5806——NanoApe Loves Sequence Ⅱ
题意: 给定一个序列,问在这个序列里有多少区间第k的的数>=m 思路: 在比赛的时候是多想了,开始像区间第k大的问题,赛后想想实在是偏了. 正确的解法是枚举起点然后用尺取法维护一段区间,直到找到 ...
- hdu4585 amp; BestCoder Round #1 项目管理(vector应用)
主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4858 项目管理 Time Limit: 2000/1000 MS (Java/Others) M ...
- 矩阵快速幂---BestCoder Round#8 1002
当要求递推数列的第n项且n很大时,怎么快速求得第n项呢? 可以用矩阵快速幂来加速计算. 我们可以用矩阵来表示数列递推公式 比如fibonacci数列 可以表示为 [f(n) f(n-1)] = [ ...
- hdu4932 Miaomiao#39;s Geometry (BestCoder Round #4 枚举)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4932 Miaomiao's Geometry Time Limit: 2000/1000 MS (Ja ...
- 贪心/二分查找 BestCoder Round #43 1002 pog loves szh II
题目传送门 1 /* 2 贪心/二分查找:首先对ai%=p,然后sort,这样的话就有序能使用二分查找.贪心的思想是每次找到一个aj使得和为p-1(如果有的话) 3 当然有可能两个数和超过p,那么an ...
- 贪心 BestCoder Round #39 1001 Delete
题目传送门 1 /* 2 贪心水题:找出出现次数>1的次数和res,如果要减去的比res小,那么总的不同的数字tot不会少: 3 否则再在tot里减去多余的即为答案 4 用set容器也可以做,思 ...
- HDU 5228 ZCC loves straight flush( BestCoder Round #41)
题目链接:ZCC loves straight flush 题面: ZCC loves straight flush Time Limit: 2000/1000 MS (Java/Others) ...
最新文章
- Swift之Vision 图像识别框架
- 【Flutter】Dart 数据类型 Map 类型 ( 创建 Map 集合 | 初始化 Map 集合 | 遍历 Map 集合 )
- python 函数装饰器_python函数装饰器的用法
- gradle编译出错:Execution failed for task #39;:app:compileTestDebugJava#39;.
- 程序员公开上班摸鱼神器!有了它,老板都不好意思打扰你!
- git安装后找不见版本_无法安装最新版本的Gitlab
- 使用Go语言创建静态文件服务器
- 解析Java的JNI编程中的对象引用与内存泄漏问题
- git的丰富实用经验
- SREng 使用指南(一)SREng简介
- uvaoj 10066 - The Twin Towers 最长公共子序列(LCS)
- 以太坊ETH(windows)配置
- 【信息安全】数据安全与信息安全
- `Caché/IRIS` 代码优化效率提升十一条 - 持续更新
- docker _port is already allocated错误
- 基于Redisson实现的延时队列RedissonDelayedQueue实现websocket服务端心跳监听
- 【转载】Spring5源码调试环境搭建
- 某计算机无法访问域名,在某台主机上无法访问域名为www.bbb.cn的网站,而局域网中的其他主机可..._考试资料网...
- 用友u8文件服务器备份,用友u8 数据备份到云服务器
- 《2008胡润IT富豪榜》