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. [转载]文件系统缓存dirty_ratio与dirty_background_ra

    原文地址:文件系统缓存dirty_ratio与dirty_background_ratio两个参数区别作者:vincent 这两天在调优数据库性能的过程中需要降低操作系统文件Cache对数据库性能的影 ...

  2. 利用Tensorflow进行自然语言处理(NLP)系列之一Word2Vec

    同步笔者CSDN博客(https://blog.csdn.net/qq_37608890/article/details/81513882). 一.概述 本文将要讨论NLP的一个重要话题:Word2V ...

  3. Python Tkinter-Event

    1.点击 from tkinter import * root=Tk() def printCoords(event): print(event.x,event.y) bt1=Button(root, ...

  4. [shell] 循环判断输入值

    做个记录 until [[ $flag == "yes" || $flag == "exit" ]] do read -p "请确认统一/合服前后数据 ...

  5. java不用任何已有方法完全自写的去重法

    package aa; class InsertSort{ private long[] a; private int nElems; //构造方法 public InsertSort(int max ...

  6. 2018-2019-20172329 《Java软件结构与数据结构》第四周学习总结

    2018-2019-20172329 <Java软件结构与数据结构>第四周学习总结 经过这样一个国庆节的假期,心中只有一个想法,这个国庆假期放的,不如不放呢!! 教材学习内容总结 < ...

  7. 《我是IT小小鸟》阅读心得

    虽然读这本书是老师布置的作业,但是读了几页后就被书中的内容所吸引住了.或许是因为我也是学这个专业的,所以书中的一些内容让我觉得非常的有兴趣.作为一个学习软件工程的大一学生还没真正的认识到这个专业的深奥 ...

  8. 【第八周】【新蜂】新NABCD

    由小组成员宫成荣撰写 一.小组项目申请时提交的NABCD: 痛点:普通的俄罗斯方块是不现实距离下一级有多远的,我们的游戏能显示距离下一等级游戏有多远.方便玩家体验. nabc: n:能满足大多数玩家的 ...

  9. 内存测试——Android Studio中对应进程的Heap

    通过Android Studio的Heap查看该程序的目前占用内存大小,多次进出界面,观察内存内存大小的变化.用Heap监测应用进程使用内存情况的步骤如下: 1. 启动Android Studio—& ...

  10. hdu 6435 CSGO(最大曼哈顿距离)

    题目链接 Problem Description You are playing CSGO. There are n Main Weapons and m Secondary Weapons in C ...