Removed Interval

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

Problem Description
Given a sequence of numbers A=a1,a2,…,aN

, a subsequence b1,b2,…,bk

of A

is referred as increasing if b1<b2<…<bk

. LY has just learned how to find the longest increasing subsequence (LIS).
Now that he has to select L

consecutive numbers and remove them from A

for some mysterious reasons. He can choose arbitrary starting position of the selected interval so that the length of the LIS of the remaining numbers is maximized. Can you help him with this problem?

 
Input
The first line of input contains a number T

indicating the number of test cases (T≤100

).
For each test case, the first line consists of two numbers N

and L

as described above (1≤N≤100000,0≤L≤N

). The second line consists of N

integers indicating the sequence. The absolute value of the numbers is no greater than 109

.
The sum of N over all test cases will not exceed 500000.

 
Output
For each test case, output a single line consisting of “Case #X: Y”. X

is the test case number starting from 1. Y

is the maximum length of LIS after removing the interval.

 
Sample Input
2
5 2
1 2 3 4 5
5 3
5 4 3 2 1
 
Sample Output
Case #1: 3
Case #2: 1
 
Source
题意:给你长度为n的序列  现在删除长度为L的连续的一段   问如何删除使得剩下的部分的LIS最大 输出最大值
题解:先处理一遍LIS dp[i]  表示以a[i]结尾的最长上升子序列的长度  对于每一段的长度L  ans=dp[i]+{i+L之后的以大于a[i]的值为起点的最长上升的长度}
与网上题解不同 这里是倒着来的。
 #include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<bitset>
#include<set>
#define ll __int64
#define mod 100000000
#define N 5e6+10
#define M 1e
using namespace std;
int t;
int n,l;
int a[],b[];
int dp[];
int ans[];
int main()
{
scanf("%d",&t);
for(int i=;i<=t;i++)
{
scanf("%d %d",&n,&l);
a[]=;
for(int j=;j<=n;j++){
scanf("%d",&a[j]);
b[j]=-a[j];
}
int exm=;
ans[exm]=a[];
dp[]=;
for(int j=;j<=n;j++)
{
if(a[j]>ans[exm]){
exm++;
ans[exm]=a[j];
dp[j]=exm;
}
else
{
int pos=lower_bound(ans+,ans+exm,a[j])-ans;
ans[pos]=a[j];
dp[j]=pos;
}
}
int an=;
for(int j=;j<=n;j++)
ans[j]=1e9;
int re=;
for(int j=n-l;j>=;j--)
{
int x=lower_bound(ans,ans+n,b[j])-ans;//
an=max(an,dp[j]+x);
int y=lower_bound(ans,ans+n,b[j+l])-ans;
ans[y]=b[j+l];
re=max(re,y+);
}
printf("Case #%d: %d\n",i,max(an,re));
}
return ;
}
/*
6
6 2
1 3 5 7 2 4
*/

HDU 5489 二分 LIS的更多相关文章

  1. 2015合肥网络赛 HDU 5489 Removed Interval LIS+线段树(树状数组)

    HDU 5489 Removed Interval 题意: 求序列中切掉连续的L长度后的最长上升序列 思路: 从前到后求一遍LIS,从后往前求一遍LDS,然后枚举切开的位置i,用线段树维护区间最大值, ...

  2. hdu 4024 二分

    转自:http://www.cnblogs.com/kuangbin/archive/2012/08/23/2653003.html   一种是直接根据公式计算的,另外一种是二分算出来的.两种方法速度 ...

  3. 【二分】【最长上升子序列】HDU 5489 Removed Interval (2015 ACM/ICPC Asia Regional Hefei Online)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5489 题目大意: 一个N(N<=100000)个数的序列,要从中去掉相邻的L个数(去掉整个区间 ...

  4. HDU 5489 Removed Interval (LIS变形)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5489 给你n个数,要删去其中连续的L个,问你删去之后的LIS最大是多少? 我们先预处理出以i下标为开头 ...

  5. hdu 5489(LIS最长上升子序列)

    题意:一个含有n个元素的数组,删去k个连续数后,最长上升子序列        /*思路参考GoZy 思路: 4 2 3 [5 7 8] 9 11 ,括号表示要删掉的数, 所以  最长上升子序列  = ...

  6. hdu 5489——Removed Interval——————【删除一段区间后的LIS】

    Removed Interval Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  7. HDU 5489 Removed Interval (LIS,变形)

    题意: 给出一个n个元素的序列,要求从中删除任一段长度为L的连续子序列,问删除后的LIS是多少?(n<=10w, L<=n ,元素可能为负) 思路: 如果会O(nlogn)求普通LIS的算 ...

  8. HDU 5489 Removed Interval 2015 ACM/ICPC Asia Regional Hefei Online (LIS变形)

    定义f[i]表示以i为开头往后的最长上升子序列,d[i]表示以i为结尾的最长上升子序列. 先nlogn算出f[i], 从i-L开始枚举f[i],表示假设i在最终的LIS中,往[0,i-L)里找到满足a ...

  9. HDU - 3564 Another LIS(LIS+线段树)

    http://acm.hdu.edu.cn/showproblem.php?pid=3564 题意 给出1~n的插入顺序,要求每次插入之后的LIS 分析 首先用线段树还原出最终序列.因为插入的顺序是按 ...

随机推荐

  1. 《零基础学JavaScript(全彩版)》学习笔记

    <零基础学JavaScript(全彩版)>学习笔记 二〇一九年二月九日星期六0时9分 前期: 刚刚学完<零基础学HTML5+CSS3(全彩版)>,准备开始学习JavaScrip ...

  2. 爬虫2.3-scrapy框架-post、shell、验证码

    目录 scrapy框架-post请求和shell 1. post请求 2. scrapy shell 3. 验证码识别 scrapy框架-post请求和shell 1. post请求 scrapy框架 ...

  3. @Resource和@Autowired的异同

    相同点: 两者都能做到注入一个Bean. 两者都可应用在Field和Method上面. 两者均为Runtime级别的Retention. 不同点: 使用的场景有差异 @Resource可应用在类(TY ...

  4. Tomcat源码学习(2)——启动过程分析

    Tomcat启动过程分析 启动 tomcat 时,Windows下执行 startup.bat :Linux下执行 startup.sh 文件,实际上最后都是调用 org.apache.catalin ...

  5. 【python 3.6】调用另一个文件的类的方法

    文件1:test12.py 文件2:test13.py 文件1 如下: #!/usr/bin/python # -*- coding: utf-8 -*- ''' ''' class abcd(obj ...

  6. UI优秀框架(库)

    1.vux 官网:https://doc.vux.li/zh-CN/ Github:https://github.com/airyland/vux 13818  Stars  3064 Forks   ...

  7. HttpServlet 详解(基础)

    HttpServlet详解 大家都知道Servlet,但是不一定很清楚servlet框架,这个框架是由两个Java包组成:javax.servlet和javax.servlet.http. 在java ...

  8. 调试和开发npm模块的方式

    ln -s(软连接) 假设my-project是运行npm模块的项目,vue-router是我们需要调试的npm模块 将vue-router下载到与my-project同级目录中. git clone ...

  9. Full Binary Tree(二叉树找规律)

    Description In computer science, a binary tree is a tree data structure in which each node has at mo ...

  10. Python学习之路7 - 生成器&迭代器

    本章内容: 列表生成式 生成器 yield 迭代器 列表生成式 当我们要定义一个列表的时候,我们通常用这种方式a = [1,2,3],但是如果我们定义了一个比较长的列表的时候,手动定义列表就会比较麻烦 ...