题目链接:

LCIS

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 458    Accepted Submission(s): 212

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 integer T, 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
 
题意:
 
求这两个序列的最长公共子序列且是一段连续的值得最长长度;
 
思路:
两个序列A,B,fa[i]表示A序列中以i为结尾的最长的子序列的最长长度,fb[i]也是一样,然后取max(min(fa[i],fb[i]));
 
AC代码:
 
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <bits/stdc++.h>
#include <stack>
#include <map> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss));
#define lson o<<1
#define rson o<<1|1
typedef long long LL; template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
if(!p) { puts("0"); return; }
while(p) stk[++ tp] = p%10, p/=10;
while(tp) putchar(stk[tp--] + '0');
putchar('\n');
} const LL mod=1e9+7;
const double PI=acos(-1.0);
const LL inf=1e18;
const int N=1e6+10;
const int maxn=1e5+10;
const double eps=1e-12; int n,m,a[maxn],b[maxn],fa[N],fb[N]; int main()
{
int t;
read(t);
while(t--)
{
read(n);read(m);
For(i,1,n)read(a[i]);
For(i,1,m)read(b[i]);
For(i,1,n)fa[a[i]-1]=fa[a[i]]=0,fb[a[i]-1]=fb[a[i]]=0;
For(i,1,m)fa[b[i]-1]=fa[b[i]]=0,fb[b[i]-1]=fb[b[i]]=0;
For(i,1,n)fa[a[i]]=fa[a[i]-1]+1;
For(i,1,m)fb[b[i]]=fb[b[i]-1]+1;
int ans=0;
for(int i=1;i<=n;i++)ans=max(ans,min(fa[a[i]],fb[a[i]]));
printf("%d\n",ans);
}
return 0;
}

  

hdu-5904 LCIS(水题)的更多相关文章

  1. HDU 5904 - LCIS (BestCoder Round #87)

    HDU 5904 - LCIS [ DP ]    BestCoder Round #87 题意: 给定两个序列,求它们的最长公共递增子序列的长度, 并且这个子序列的值是连续的 分析: 状态转移方程式 ...

  2. HDU5904 LCIS 水题

    http://acm.hdu.edu.cn/showproblem.php?pid=5904:// 说是LCIS其实和LCIS没有一点儿关系的水题. 代码 #include<cstdio> ...

  3. hdu 5210 delete 水题

    Delete Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5210 D ...

  4. hdu 1251 (Trie水题)

    统计难题 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131070/65535 K (Java/Others)Total Submi ...

  5. HDU 5703 Desert 水题 找规律

    已知有n个单位的水,问有几种方式把这些水喝完,每天至少喝1个单位的水,而且每天喝的水的单位为整数.看上去挺复杂要跑循环,但其实上,列举几种情况之后就会发现是找规律的题了= =都是2的n-1次方,而且这 ...

  6. HDU 4493 Tutor 水题的收获。。

    题目: http://acm.hdu.edu.cn/showproblem.php?pid=4493 题意我都不好意思说,就是求12个数的平均数... 但是之所以发博客,显然有值得发的... 这个题最 ...

  7. hdu 4802 GPA 水题

    GPA Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4802 Des ...

  8. hdu 4493 Tutor 水题

    Tutor Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4493 D ...

  9. hdu 5495 LCS 水题

    LCS Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5495 Descr ...

随机推荐

  1. 【Effective Java】4、覆盖equals时请遵守通用约定

    package cn.xf.cp.ch02.item8.transitivity; public class Point { private final int x; private final in ...

  2. MySQL 数据库 InnoDB 和 MyISAM 数据引擎的差别

    InnoDB和MyISAM是在使用MySQL最常用的两个表类型,各有优缺点,视具体应用而定.基本的差别为:MyISAM类型不支持事务处理等高级处理,而InnoDB类型支持.MyISAM类型的表强调的是 ...

  3. 我所了解的WEB开发(2) - PS切片

    PS对于WEB设计和前端开发来说都是不可或缺的工具,基本的用途是用来处理网站的LOGO.Banner 以及按钮图标来着,但是一旦遇上要把整个PSD文件转成网页就让人非常头痛了,可能还不太专业.后来在公 ...

  4. Atitit.木马 病毒 免杀 技术 360免杀 杀毒软件免杀 原理与原则 attilax 总结

    Atitit.木马 病毒 免杀 技术 360免杀 杀毒软件免杀 原理与原则 attilax 总结 1. ,免杀技术的用途2 1.1. 病毒木马的编写2 1.2. 软件保护所用的加密产品(比如壳)中,有 ...

  5. VS2010运行正常的控制台程序在VS2015中出现乱码的解决方法

    以前在Visual Stuido 2010中运行正常的控制台程序,在Visual Studio 2015中出现乱码,找到<Visual Studio 2015的坑:中文字符串编译后成乱码> ...

  6. Lucene总体架构

    Lucene总的来说是:• 一个高效的,可扩展的,全文检索库.• 全部用Java实现,无须配置.• 仅支持纯文本文件的索引(Indexing)和搜索(Search).• 不负责由其他格式的文件抽取纯文 ...

  7. Python基础(5)--字典

    字典由多个键及与其对应的值构成的对组成(把键值对成为项),每个键和它的值之间用冒号(:)隔开,项之间用逗号(,)隔开,而整个字典由一对大括号括起来.空字典由两个大括号组成:{} 本文地址:http:/ ...

  8. 干货-iOS、mac开源项目及库,以后我也会持续更新。

    昨晚在网上看的干货,直接分享给大家了,觉得有用的,直接fork吧. https://github.com/Brances/TimLiu-iOS

  9. Objective-C Reflection(Objective-C 反射机制)实用随笔笔记(持续更新)

    前言:本篇文章就"Objective-C 反射机制"使用方面进行叙述,不会涉及太多理论论述,因为"Objective-C 反射机制"理论论述在网上搜索一大把,本 ...

  10. RunTime(运行时机制)

    1>runtime实现的机制是什么,怎么用,一般用于干嘛? 这个问题我就不跟大家绕弯子了,直接告诉大家, runtime是一套比较底层的纯C语言API, 属于1个C语言库, 包含了很多底层的C语 ...