题目链接:

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. TCMalloc优化MySQL、Nginx内存管理

    TCMalloc的全称为Thread-Caching Malloc,是谷歌开发的开源工具google-perftools中的一个成员. 与标准的glibc库的Malloc相比,TCMalloc库在内存 ...

  2. Java8 如何进行stream reduce,collection操作

    Java8 如何进行stream reduce,collection操作 2014-07-16 16:42 佚名 oschina 字号:T | T 在java8 JDK包含许多聚合操作(如平均值,总和 ...

  3. 【OpenCV】OpenCV中GPU模块使用

    CUDA基本使用方法 在介绍OpenCV中GPU模块使用之前,先回顾下CUDA的一般使用方法,其基本步骤如下: 1.主机代码执行:2.传输数据到GPU:3.确定grid,block大小: 4.调用内核 ...

  4. Java生成公私钥对

    public static synchronized KeyPair generateRSAKeyPair(int keysize, BigInteger publicExponent) { try ...

  5. Erlang高阶函数

    对于函数式语言来说,函数也想普通的数据类型一样无处不在.函数即可以当成参数进行传递,也可以当成函数的返回值.当我第一次学习函数式编程的时候,我被这样的写法弄的头昏脑涨.下面我举例说明下(例子摘录自Le ...

  6. ASP.NET MVC下判断用户登录和授权的方法

    日常开发的绝大多数系统中,都涉及到管理用户的登录和授权问题.登录功能(Authentication),针对于所有用户都开放:而授权(Authorization),则对于某种用户角色才开放. 在asp. ...

  7. 拖拽改变div的大小

    拖拽改变div的大小 <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type&qu ...

  8. Win10 FaceAPI小demo开发问题汇总

    Win10 FaceAPI小demo开发问题汇总 最近使用微软牛津计划做一个小demo,使用FaceAPI做一个小应用,实现刷脸的功能.开发的过程中用到几个问题,具体如下: Stream 与IRand ...

  9. Mybatis学习记录(五)----Mybatis的动态SQL

    1.  什么是动态sql mybatis核心 对sql语句进行灵活操作,通过表达式进行判断,对sql进行灵活拼接.组装. 1.1 需求 用户信息综合查询列表和用户信息查询列表总数这两个statemen ...

  10. Java反射中的getClass()方法

    Java反射学习 所谓反射,可以理解为在运行时期获取对象类型信息的操作.传统的编程方法要求程序员在编译阶段决定使用的类型,但是在反射的帮助下,编程人员可以动态获取这些信息,从而编写更加具有可移植性的代 ...