题目传送门

题意:求删掉连续L长度后的LIS

分析:记rdp[i]表示以a[i]为开始的LIS长度,用nlogn的办法,二分查找-a[i]。dp[i]表示以a[i]为结尾并且删去[i-L-1, i-1]的LIS,ans = max (dp[i] + rdp[i] - 1),还要特别考虑删去最后L的长度

/************************************************
* Author :Running_Time
* Created Time :2015/9/29 星期二 15:11:29
* File Name :F.cpp
************************************************/ #include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std; #define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int N = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const double EPS = 1e-8;
int a[N];
int dp[N], rdp[N];
int d[N]; int main(void) {
int T, cas = 0; scanf ("%d", &T);
while (T--) {
int n, L; scanf ("%d%d", &n, &L);
for (int i=1; i<=n; ++i) {
scanf ("%d", &a[i]);
} int ans = 0;
memset (d, INF, sizeof (d));
for (int i=n; i>=1; --i) {
int k = lower_bound (d+1, d+1+n, -a[i]) - d;
d[k] = -a[i];
rdp[i] = k; //以a[i]为开始的LIS长度
}
memset (d, INF, sizeof (d));
for (int i=1; i<=n; ++i) {
if (i - L - 1 >= 1) d[lower_bound (d+1, d+1+n, a[i-L-1]) - d] = a[i-L-1];
dp[i] = lower_bound (d+1, d+1+n, a[i]) - d; //以a[i]为结尾的LIS长度
if (i > L) ans = max (ans, dp[i] + rdp[i] - 1);
}
if (n > L) ans = max (ans, (int) (lower_bound (d+1, d+1+n, a[n-L]) - d)); //删去最后的L长度
printf ("Case #%d: %d\n", ++cas, ans);
} return 0;
}

  

LIS(变形) HDOJ 5489 Removed Interval的更多相关文章

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

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

  2. hdu 5489——Removed Interval——————【删除一段区间后的LIS】

    Removed Interval Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  3. HDU 5489 Removed Interval (LIS变形)

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

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

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

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

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

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

  7. HDU 5489 Removed Interval

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

  8. HDU 5489 Removed Interval DP 树状数组

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

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

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

随机推荐

  1. 在MVC中使用泛型仓储模式和工作单元来进行增删查改

    原文链接:http://www.c-sharpcorner.com/UploadFile/3d39b4/crud-operations-using-the-generic-repository-pat ...

  2. Java Management Extensions (JMX) Flume

    Lesson: Overview of the JMX Technology (The Java™ Tutorials > Java Management Extensions (JMX)) h ...

  3. 使用forever让node.js持久运行

    何为forever?forever可以看做是一个nodejs的守护进程,能够启动,停止,重启我们的app应用. npm install forever -g #安装 forever start app ...

  4. c语言基本函数

    1. 用宏定义写出swap(x,y) #define swap(x, y) x = x + y; y = x - y; x = x - y; 2.数组a[N],存放了1至N-1个数,其中某个数重复一次 ...

  5. Spring Boot2.0+Redis+Ehcache实现二级缓存

    EHCache 本地缓存 Redis 分布式缓存(可以共享) 一级 Redis 二级Ehcache    当redis挂了 有备胎 反之: 先走本地,本地没有再走网络  尽量少走Redis  效率会高 ...

  6. 【原】WPF客户端只能启动一次

    public partial class App : Application { System.Threading.Mutex mutex; public App() { this.Startup + ...

  7. 推箱子 Sokoban(华中农业比赛)

    点这里 打开题目链接   点击打开链接 题目就是我们玩过的推箱子: 一顿暴力广搜:加状态标记.状态压缩需要用到一个类似于康拓的思想来压缩:所以容易TLE,搜索就是用一个int型的数字来表示一个状态, ...

  8. js获取form的方法

    先来看下面代码: ? <html> <head> <scirpy> window.onload=function(){    var f1=document.f1; ...

  9. jsch文件下载功能

    转载:http://www.cnblogs.com/longyg/archive/2012/06/25/2561332.html 上一篇讲述了使用JSch实现文件上传的功能,这一篇主要讲述一下JSch ...

  10. MyBatis学习 之 五、MyBatis配置文件

    在定义sqlSessionFactory时需要指定MyBatis主配置文件: <bean id="sqlSessionFactory" class="org.myb ...