Removed Interval

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

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最大值。并且每次更新删除区间的前面能形成的LIS。。。。。。。。。。。

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+200;
const int INF = 0x3f3f3f3f;
int a[maxn],b[maxn],endminv[maxn];
int dp[maxn];
int BinSearch(int l,int r,int key,int typ){ //二分求解小于等于key的第一个位置
int md; //二分求解大于等于key的第一个位置
if(typ==0){
while(l<r){
md=(l+r)/2;
if(endminv[md]>key){
l=md+1;
}else if(endminv[md]<key){
r=md;
}else{
return md;
}
}
return l;
}else{
while(l<r){
md=(l+r)/2;
if(endminv[md]>key){
r=md;
}else if(endminv[md]<key){
l=md+1;
}else{
return md;
}
}
return l;
}
} int main(){
int T,n,L,cnt=0;
scanf("%d",&T);
while(T--){
scanf("%d%d",&n,&L);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
}
for(int i=0;i<=n;i++)
endminv[i]=-INF;
for(int i=n;i>=1;i--){ //逆序得到最长递减子序列,那么正序依然是递增的
int x=BinSearch(1,n,a[i],0);
endminv[x]=a[i];
dp[i]=x; //以a[i]结尾的最长递减子序列长度
}
memset(endminv,INF,sizeof(endminv));
int ans=0; int len=1;
for(int i=L+1;i<=n;i++){ //枚举要删除的区间的右端点
int x=BinSearch(1,n,a[i],1);
ans=max(ans,dp[i]+x-1);//删除区间后前后能拼接成的LIS长度
x=BinSearch(1,n,a[i-L],1); //枚举区间左边能形成的LIS
endminv[x]=a[i-L];
len=max(len,x+1); //对于区间左边正常求LIS
}
printf("Case #%d: %d\n",++cnt,max(ans,len-1));
}
return 0;
}

  

hdu 5489——Removed Interval——————【删除一段区间后的LIS】的更多相关文章

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

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

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

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

  3. HDU 5489 Removed Interval

    题意:求一段序列中删掉L个连续元素后的LIS. 解法:我的想法很复杂= =怎么说呢……首先用nlogn的方法求LIS得到的序列dp的第i项的意义为上升子序列所有长度为i的序列结尾元素的最小值,那么先倒 ...

  4. HDU 5489 Removed Interval (LIS变形)

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

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

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

  6. HDU 5489 Removed Interval DP 树状数组

    题意: 给一个长度为\(N\)的序列,要删除一段长为\(L\)的连续子序列,问所能得到的最长的\(LIS\)的长度. 分析: 设\(f(i)\)表示以\(a_i\)结尾的\(LIS\)的长度,设\(g ...

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

  8. LIS(变形) HDOJ 5489 Removed Interval

    题目传送门 题意:求删掉连续L长度后的LIS 分析:记rdp[i]表示以a[i]为开始的LIS长度,用nlogn的办法,二分查找-a[i].dp[i]表示以a[i]为结尾并且删去[i-L-1, i-1 ...

  9. Hdu 5489 合肥网络赛 1009 Removed Interval

    跳跃式LIS(nlogn),在普通的转移基础上增加一种可以跨越一段距离的转移,用一颗新的树状数组维护,同时,我们还要维护跨越完一次后面的转移,所以我用了3颗树状数组.. 比赛的时候一句话位置写错了,然 ...

随机推荐

  1. 使用py 和flask 实现的服务器系统目录浏览,日志文件实时显示到网页的功能

    看日志希望带有彩色,希望从浏览器上看到,不用连到机器上看. 浏览系统的文件夹,scan + 系统文件夹的层级名字当做url路由,可以深层次看到机器上任何层级的文件夹,实现系统文件夹浏览下载. 如果是点 ...

  2. sql server 表索引碎片处理

    DBCC SHOWCONTIG (Transact-SQL) SQL Server 2005 其他版本 更新日期: 2007 年 9 月 15 日 显示指定的表或视图的数据和索引的碎片信息. 重要提示 ...

  3. java中的equals方法

    这个方法首先比较的是两个对象的地址是否相同,如果相同直接返回true, 否则, (1)如果是string类型的先比较是否是string类型,是的话,再比较是否长度相同,相同的话再比较,每个字符是否相同 ...

  4. RubyGems 镜像 - 淘宝网

    为什么有这个? 由于国内网络原因(你懂的),导致 rubygems.org 存放在 Amazon S3 上面的资源文件间歇性连接失败.所以你会与遇到 gem install rack 或 bundle ...

  5. CentOS7下yum方式安装mysql5.6

    在Centos7中用MariaDB代替了mysql数据库.所以在新安装MySQL前必须做好对系统的清理工作. 一.清理CentOS7下的MariaDB. [root@localhost ~]#rpm ...

  6. HDU - 5542 The Battle of Chibi(LIS+树状数组优化)

    The Battle of Chibi Cao Cao made up a big army and was going to invade the whole South China. Yu Zho ...

  7. Note: Migratory Compression: Coarse-grained Data Reordering to Improve Compressibility

    思路/方法 设计了Migratory Compression. 调整chunk相对位置,将相似chunk排列在一起,通过压缩来减少data store占用的实际存储空间. https://en.wik ...

  8. DNS 网关 路由 交换机 网桥 协议 服务器 这些都是什么关系?

    来源:知乎 服务器:为你提供服务的机器.相当于马路边上的各种店面.虽然理论上任何一户人家都能开店为你提供服务,但是因为各种硬件资源限制而不适合开店.比如:小区道路比较窄(宽带带宽比较窄).家里地方太小 ...

  9. 解读人:朱月琴,Hippocampal proteomic alteration in triple transgenic mouse model of Alzheimer’s disease and implication of PINK 1 regulation in donepezil treatment

    文章中文名:阿尔茨海默病三联转基因小鼠模型的海马蛋白质组学改变及Donepezil治疗中PINK 1调节的意义 发表时间:(2019年4月) IF:3.95 单位:澳门大学,威斯康星大学,暨南大学,广 ...

  10. springmvc json 简单例子

    1.控制器层: @RequestMapping("/json.do") @ResponseBody //将会把返回值 转换为json对象 public List<User&g ...