Removed Interval

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
 
题意:一个含有n个元素的数组,删去k个连续数后,求LIS
题解:定义l[i]为  以第i个数结尾,删除i-k-1到i-1这k个数的LIS
        定义r[i]为 以i开头到n的LIS
       因为这样我们会忽略删除最后K个数的情况,所以我们n+1   最后一个元素赋值为无穷大
       答案就是 l[i]+r[i]-2;
///

#include<bits/stdc++.h>
using namespace std;
//#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std ;
typedef long long ll;
#define mem(a) memset(a,0,sizeof(a))
#define pb push_back
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){
if(ch=='-')f=-;ch=getchar();
}
while(ch>=''&&ch<=''){
x=x*+ch-'';ch=getchar();
}return x*f;
}
//****************************************
const int N=+;
#define mod 1000000007
#define inf 1000000007 int b[N],a[N],dp[N],l[N],r[N],n,L; int main() {
int T=read();int oo=;
while(T--) {
mem(a),mem(b);
scanf("%d%d",&n,&L);
for(int i=;i<=n;i++) {
scanf("%d",&a[i]);
}a[++n]=inf;
for(int i=;i<=n;i++) {
b[n-i+]=-a[i];
}
fill(dp+,dp+n+,inf+);
for(int i=L+;i<=n;i++) {
int tmp=lower_bound(dp+,dp+n+,a[i])-dp;
l[i]=tmp;
tmp=lower_bound(dp+,dp+n+,a[i-L])-dp;
dp[tmp]=a[i-L];
}
fill(dp+,dp+n+,inf);
for(int i=;i<=n;i++) {
int tmp=lower_bound(dp+,dp+n+,b[i])-dp;
r[n-i+]=tmp;
dp[tmp]=b[i];
}
//for(int i=1;i<=n;i++)cout<< l[i]<<" ";
//cout<<endl;
//for(int i=1;i<=n;i++)cout<< r[i]<<" ";
int ans=;
for(int i=L+;i<=n;i++) {
ans=max(ans,l[i]+r[i]-);
}
printf("Case #%d: ",oo++);
cout<<ans<<endl;
}
return ;
}

代码

HDU5489 LIS变形的更多相关文章

  1. 九度 1557:和谐答案 (LIS 变形)

    题目描述: 在初试即将开始的最后一段日子里,laxtc重点练习了英语阅读的第二部分,他发现了一个有意思的情况.这部分的试题最终的答案总是如下形式的:1.A;2.C;3.D;4.E;5.F.即共有六个空 ...

  2. hdu 1087(LIS变形)

    Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  3. UVA 437 巴比伦塔 【DAG上DP/LIS变形】

    [链接]:https://cn.vjudge.net/problem/UVA-437 [题意]:给你n个立方体,让你以长宽为底,一个个搭起来(下面的立方体的长和宽必须大于上面的长和宽)求能得到的最长高 ...

  4. UVa 1471 (LIS变形) Defense Lines

    题意: 给出一个序列,删掉它的一个连续子序列(该子序列可以为空),使得剩下的序列有最长的连续严格递增子序列. 分析: 这个可以看作lrj的<训练指南>P62中讲到的LIS的O(nlogn) ...

  5. hdu5773--The All-purpose Zero(LIS变形)

    题意:给一个非负整数的数列,其中0可以变成任意整数,包括负数,求最长上升子序列的长度. 题解:LIS是最简单的DP了,但是变形之后T^T真的没想到.数据范围是10^5,只能O(nlogn)的做法,所以 ...

  6. UVA1471( LIS变形)

    这是LIS的变形,题意是求一个序列中去掉某个连续的序列后,能得到的最长连续递增序列的长度. 用DP的解法是:吧这个序列用数组a来记录,再分别用两个数组f记录以i结尾的最长连续递增序列的长度,g[i]记 ...

  7. HDU-1160.FatMouse'sSpeed.(LIS变形 + 路径打印)

    本题大意:给定一定数量的数对,每个数保存着一只老鼠的质量和速度,让你求出一个最长序列,这个序列按照质量严格递增,速度严格递减排列,让你输出这个序列的最长长度,并且输出组成这个最长长度的序列的对应的老鼠 ...

  8. POJ 1836-Alignment(DP/LIS变形)

    Alignment Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 13465   Accepted: 4336 Descri ...

  9. poj 1836 LIS变形

    题目链接http://poj.org/problem?id=1836 Alignment Time Limit: 1000MS   Memory Limit: 30000K Total Submiss ...

随机推荐

  1. OFDM同步算法之Schmidl算法

    Schmidl算法代码 算法原理 训练序列结构 T=[A A],其中A表示复伪随机序列PN,进行N/2点ifft变换得到的符号序列 \[M(d)=\frac{\left | P(d) \right | ...

  2. node.js安装及其环境配置

    nodejs: 实际上是采用google的chrome浏览器V8引擎,由C++编写的 本质上是一个javascript的运行环境 浏览器引擎可以解析js代码 nodejs可以解析js代码,没有浏览器端 ...

  3. enc28j60网卡驱动模块添加进linux内核,Kconfig,Makefile配置过程

    这里是要把http://www.cnblogs.com/hackfun/p/6260396.html中的enc28j60网卡驱动模块,添加到2.6.22.6内核中,这个模块代码不需要任何修改.只需要在 ...

  4. iOS CoreData 开发之数据模型关系

    接着上一篇,上一篇中,我们简单的实现了一个用户实体,本次添加一个用户信息实体,与用户实体相关联,关系为1:1. 新建一个实体UserInfo:

  5. 常见Android安装启动失败问题

    1.INSTALL_FAILED_VERSION_DOWNGRADE版本过低2.Failed to install Funm_AND.apk on device 'QWOJLVR8KNHYA6NR': ...

  6. Linux Shell ssh登录脚本

    Linux 登陆服务器敲命令太多,某时候确实不便,所以就用shell写了一个  我的blog地址: http://www.cnblogs.com/caoguo 一.说明 支持秘密和密钥两种格式 用户名 ...

  7. 【LeetCode】1、Two Sum

    题目等级:Easy 题目描述:   Given an array of integers, return indices of the two numbers such that they add u ...

  8. java 导入导出的 命令

    $exp lddba/ld_321@192.168.1.3/testora file=E:\db_bak\ld20170219_1testora.dmp log=E:\db_bak\ld2017021 ...

  9. Entertainment Box Gym100781E(数据结构+贪心)

    Entertainment Box 题意: 有n个节目,每个节目给出开始时间(st)和结束时间(en): 有k个内存条这k个内存条可以同时存储节目.如果节目j的开始时间stj  大于等于节目i的结束时 ...

  10. Linux:文本处理工具

    闲话少说,列出工具: ========================这些是查看文本用的=========================== 1,cat  用法:cat >f1 直接创建或覆盖 ...