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. printFinal用法示例

    printFinal是一个基于jQuery的打印插件,支持打印预览,使用很简单,废话不多多说,直接上代码. <!DOCTYPE html PUBLIC "-//W3C//DTD XHT ...

  2. python os os.path模块学习笔记

    #!/usr/bin/env python #coding=utf-8 import os #创建目录 os.mkdir(r'C:\Users\Silence\Desktop\python') #删除 ...

  3. Python 之mysql类封装

    import pymysql class MysqlHelper(object): conn = None def __init__(self, host, username, password, d ...

  4. Redis 之服务器集群配置

    常见的集群架构如图: redis操作过程中数据同步的函数调用关系: 集群搭建: 1.修改3个redis.config 文件的: 2.启动2个redis服务器 当杀掉redis主进程Master时,由于 ...

  5. php 在不知道字符串有多长的情况下,如何去除前三个字符?

    $string='字符串';$subject=substr_replace(string,'',0,3);

  6. sysbench测试阿里云ECS云磁盘的IOPS,吞吐量

    测试阿里云ECS 对象:在aliyun上买了一个ECS附加的云盘,使用sysbench测试云盘的IOPS和吞吐量 sysbench prepare 准备文件,10个文件,1个1G [root@iZwz ...

  7. 37.分组聚合操作—其他metric

    课程大纲     要学其他的metric(count,avg,max,min,sum) count:bucket,terms,自动就会有一个doc_count,就相当于是count avg:avg a ...

  8. 手机版地图api

    手机版地图api一: <iframe style="height:300px;" src="http://map.baidu.com/mobile/webapp/s ...

  9. Java Web学习总结(23)——Distributed Configuration Management Platform(分布式配置管理平台)

    专注于各种 分布式系统配置管理 的通用组件/通用平台, 提供统一的配置管理服务. 主要目标: 部署极其简单:同一个上线包,无须改动配置,即可在 多个环境中(RD/QA/PRODUCTION) 上线 部 ...

  10. JavaWeb+MySql分页封装

    前段时间因为需要所以写一个JavaWeb+MySql的分页封装类,附上代码.技术有限写得不好请多多指教. 1.首先贴上Eneity类 package com.zx.pageUtil; import j ...