题目链接:点击打开链接

1003-LCIS

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 243    Accepted Submission(s): 98
Problem Description
Alex has two sequences a1,a2,...,an and b1,b2,...,bm. He wants find a longest common subsequence that consists of consecutive values in increasing order.
Input
There are multiple test cases. The first line of input contains an integerT, indicating the number of test cases. For each test case:

The first line contains two integers n and m(1≤n,m≤100000) -- the length of two sequences. The second line contains n integers: a1,a2,...,an(1≤ai≤106). The third line contains n integers: b1,b2,...,bm(1≤bi≤106).

There are at most 1000 test cases and the sum of n and m does not exceed 2×106.

Output
For each test case, output the length of longest common subsequence that consists of consecutive values in increasing order.
Sample Input
3 3 3 1 2 3 3 2 1 10 5 1 23 2 32 4 3 4 5 6 1 1 2 3 4 5 1 1 2 1
Sample Output
1 5 0
Source
BestCoder Round #87 

题解:

令f(i)f(i)是以a_ia ​i​​结尾的最大值, g(i)g(i)是以b_ib​i​​结尾的最大值. 答案就是\max_{a_i = b_j} {\min(f(i),g(j)}max​a​i​​=b​j​​​​{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】)相关推荐

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

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

  2. 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 ...

  3. BestCoder Round #86 1003 HDU 5806——NanoApe Loves Sequence Ⅱ

    题意: 给定一个序列,问在这个序列里有多少区间第k的的数>=m 思路: 在比赛的时候是多想了,开始像区间第k大的问题,赛后想想实在是偏了. 正确的解法是枚举起点然后用尺取法维护一段区间,直到找到 ...

  4. hdu4585 amp; BestCoder Round #1 项目管理(vector应用)

    主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4858 项目管理 Time Limit: 2000/1000 MS (Java/Others)    M ...

  5. 矩阵快速幂---BestCoder Round#8 1002

    当要求递推数列的第n项且n很大时,怎么快速求得第n项呢? 可以用矩阵快速幂来加速计算. 我们可以用矩阵来表示数列递推公式 比如fibonacci数列 可以表示为 [f(n)   f(n-1)] = [ ...

  6. 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 ...

  7. 贪心/二分查找 BestCoder Round #43 1002 pog loves szh II

    题目传送门 1 /* 2 贪心/二分查找:首先对ai%=p,然后sort,这样的话就有序能使用二分查找.贪心的思想是每次找到一个aj使得和为p-1(如果有的话) 3 当然有可能两个数和超过p,那么an ...

  8. 贪心 BestCoder Round #39 1001 Delete

    题目传送门 1 /* 2 贪心水题:找出出现次数>1的次数和res,如果要减去的比res小,那么总的不同的数字tot不会少: 3 否则再在tot里减去多余的即为答案 4 用set容器也可以做,思 ...

  9. HDU 5228 ZCC loves straight flush( BestCoder Round #41)

    题目链接:ZCC loves straight flush 题面: ZCC loves straight flush Time Limit: 2000/1000 MS (Java/Others)    ...

最新文章

  1. Swift之Vision 图像识别框架
  2. 【Flutter】Dart 数据类型 Map 类型 ( 创建 Map 集合 | 初始化 Map 集合 | 遍历 Map 集合 )
  3. python 函数装饰器_python函数装饰器的用法
  4. gradle编译出错:Execution failed for task #39;:app:compileTestDebugJava#39;.
  5. 程序员公开上班摸鱼神器!有了它,老板都不好意思打扰你!
  6. git安装后找不见版本_无法安装最新版本的Gitlab
  7. 使用Go语言创建静态文件服务器
  8. 解析Java的JNI编程中的对象引用与内存泄漏问题
  9. git的丰富实用经验
  10. SREng 使用指南(一)SREng简介
  11. uvaoj 10066 - The Twin Towers 最长公共子序列(LCS)
  12. 以太坊ETH(windows)配置
  13. 【信息安全】数据安全与信息安全
  14. `Caché/IRIS` 代码优化效率提升十一条 - 持续更新
  15. docker _port is already allocated错误
  16. 基于Redisson实现的延时队列RedissonDelayedQueue实现websocket服务端心跳监听
  17. 【转载】Spring5源码调试环境搭建
  18. 某计算机无法访问域名,在某台主机上无法访问域名为www.bbb.cn的网站,而局域网中的其他主机可..._考试资料网...
  19. 用友u8文件服务器备份,用友u8 数据备份到云服务器
  20. 《2008胡润IT富豪榜》

热门文章

  1. 生物智能与AI——关乎创造、关乎理解
  2. idea 注释头部设置24小时
  3. OpenWrt系统下挂载阿里云盘提供webDAV服务再用kodi打造家庭影院
  4. bzoj4476: [Jsoi2015]送礼物
  5. oracle字符集有哪几种,Oracle字符集的三大类型
  6. 法国CONDENSE珂蒂丝官宣苏菲-玛索成为香水系列代言人
  7. 记账理财,就选我爱管账
  8. 语言库函数大全--资料收集整理
  9. asps英文_汽车英文名称缩写(大全)
  10. 统考英语计算机报名入口奥鹏,考试服务