hdu 5489——Removed Interval——————【删除一段区间后的LIS】
Removed Interval
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1086 Accepted Submission(s): 392
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?
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.
题目大意:给你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】的更多相关文章
- 2015合肥网络赛 HDU 5489 Removed Interval LIS+线段树(树状数组)
HDU 5489 Removed Interval 题意: 求序列中切掉连续的L长度后的最长上升序列 思路: 从前到后求一遍LIS,从后往前求一遍LDS,然后枚举切开的位置i,用线段树维护区间最大值, ...
- HDU 5489 Removed Interval (LIS,变形)
题意: 给出一个n个元素的序列,要求从中删除任一段长度为L的连续子序列,问删除后的LIS是多少?(n<=10w, L<=n ,元素可能为负) 思路: 如果会O(nlogn)求普通LIS的算 ...
- HDU 5489 Removed Interval
题意:求一段序列中删掉L个连续元素后的LIS. 解法:我的想法很复杂= =怎么说呢……首先用nlogn的方法求LIS得到的序列dp的第i项的意义为上升子序列所有长度为i的序列结尾元素的最小值,那么先倒 ...
- HDU 5489 Removed Interval (LIS变形)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5489 给你n个数,要删去其中连续的L个,问你删去之后的LIS最大是多少? 我们先预处理出以i下标为开头 ...
- 【二分】【最长上升子序列】HDU 5489 Removed Interval (2015 ACM/ICPC Asia Regional Hefei Online)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5489 题目大意: 一个N(N<=100000)个数的序列,要从中去掉相邻的L个数(去掉整个区间 ...
- HDU 5489 Removed Interval DP 树状数组
题意: 给一个长度为\(N\)的序列,要删除一段长为\(L\)的连续子序列,问所能得到的最长的\(LIS\)的长度. 分析: 设\(f(i)\)表示以\(a_i\)结尾的\(LIS\)的长度,设\(g ...
- 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 ...
- LIS(变形) HDOJ 5489 Removed Interval
题目传送门 题意:求删掉连续L长度后的LIS 分析:记rdp[i]表示以a[i]为开始的LIS长度,用nlogn的办法,二分查找-a[i].dp[i]表示以a[i]为结尾并且删去[i-L-1, i-1 ...
- Hdu 5489 合肥网络赛 1009 Removed Interval
跳跃式LIS(nlogn),在普通的转移基础上增加一种可以跨越一段距离的转移,用一颗新的树状数组维护,同时,我们还要维护跨越完一次后面的转移,所以我用了3颗树状数组.. 比赛的时候一句话位置写错了,然 ...
随机推荐
- VBS调用并监控记事本进程
Dim flag flag=true Set WshShell = CreateObject("WScript.Shell") '创建WScript.Shell对象 Set ...
- Ubuntu 安装Logstash
Logstash 包是从同一存储库中可用,如 Elasticsearch,和我们已经安装了该公钥,因此,让我们共创 Logstash 源列表︰ echo 'deb http://packages.el ...
- 15. CTF综合靶机渗透(八)
VM Name: BlackMarket VM Description: BlackMarket VM presented at Brisbane SecTalks BNE0x1B (28th Ses ...
- hdu1071
#include <iostream> #include <stdio.h> using namespace std; int main() { int t; double x ...
- 【转】webservice
一.WebService概念 Web Service基本概念 Web Service也叫XML Web Service WebService是一种可以接收从Internet或者Intranet上的其它 ...
- kolla制作过程中:neutron-sfc-agent 报错的问题
在使用二进制方式编译镜像的时候,neutron的sfc-agent提示如下错误ERROR:kolla.image.build:neutron-sfc-agent Failed with status: ...
- Java面向对象的三大特性 多态
多态 对象的多种形态 继承是实现多态的基础 1,引用多态 父类的引用可以指向本类的对象 父类的引用可以指向子类的对象 2,方法多态 创建本类对象时,调用的方法为本类方法 创建子 ...
- PHP 预定义常量(魔术常量)
显示当前代码在多少行__LINE__ echo __LINE__; 获取当前文件绝对路径 __FILE__ echo __FILE__; //结果为: // D:\xxxx\xxxx\xxxx\ind ...
- 洛谷P1275 魔板
P1275 魔板 题目描述 有这样一种魔板:它是一个长方形的面板,被划分成n行m列的n*m个方格.每个方格内有一个小灯泡,灯泡的状态有两种(亮或暗).我们可以通过若干操作使魔板从一个状态改变为另一个状 ...
- JSONObject,JSONArray,String,Map间的互转
引言 在平常的Web项目开发过程中,json和String.map是最常用的类型和返回结果集,其中也经常会涉及到之间的各种相互转换,下边就总结一下: 1.String转JSONObject ...