LIS(变形) HDOJ 5489 Removed Interval
题意:求删掉连续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的更多相关文章
- 2015合肥网络赛 HDU 5489 Removed Interval LIS+线段树(树状数组)
HDU 5489 Removed Interval 题意: 求序列中切掉连续的L长度后的最长上升序列 思路: 从前到后求一遍LIS,从后往前求一遍LDS,然后枚举切开的位置i,用线段树维护区间最大值, ...
- hdu 5489——Removed Interval——————【删除一段区间后的LIS】
Removed Interval Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- HDU 5489 Removed Interval (LIS变形)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5489 给你n个数,要删去其中连续的L个,问你删去之后的LIS最大是多少? 我们先预处理出以i下标为开头 ...
- HDU 5489 Removed Interval (LIS,变形)
题意: 给出一个n个元素的序列,要求从中删除任一段长度为L的连续子序列,问删除后的LIS是多少?(n<=10w, L<=n ,元素可能为负) 思路: 如果会O(nlogn)求普通LIS的算 ...
- 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 ...
- 【二分】【最长上升子序列】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
题意:求一段序列中删掉L个连续元素后的LIS. 解法:我的想法很复杂= =怎么说呢……首先用nlogn的方法求LIS得到的序列dp的第i项的意义为上升子序列所有长度为i的序列结尾元素的最小值,那么先倒 ...
- HDU 5489 Removed Interval DP 树状数组
题意: 给一个长度为\(N\)的序列,要删除一段长为\(L\)的连续子序列,问所能得到的最长的\(LIS\)的长度. 分析: 设\(f(i)\)表示以\(a_i\)结尾的\(LIS\)的长度,设\(g ...
- Hdu 5489 合肥网络赛 1009 Removed Interval
跳跃式LIS(nlogn),在普通的转移基础上增加一种可以跨越一段距离的转移,用一颗新的树状数组维护,同时,我们还要维护跨越完一次后面的转移,所以我用了3颗树状数组.. 比赛的时候一句话位置写错了,然 ...
随机推荐
- (org.openqa.selenium.WebDriverException: Unable to launch the app: Error: Trying to start logcat capture but it's already started! )错误解决办法
新增: capabilities.setCapability("autoLaunch",false); 将setup中的: driver = new AndroidDriver(n ...
- 启用了不安全的HTTP方法解决办法 IBM APPSCAN
启用了不安全的HTTP方法解决办法 IBM APPSCAN 安全风险: 可能会在Web 服务器上上载.修改或删除Web 页面.脚本和文件. 可能原因: Web 服务器 ...
- springboot和redis处理页面缓存
页面缓存是应对高并发的一个比较常见的方案,当请求页面的时候,会先查询redis缓存中是否存在,若存在则直接从缓存中返回页面,否则会通过代码逻辑去渲染页面,并将渲染后的页面缓存到redis中,然后返回. ...
- sql语句,无法绑定由多个部分组成的标识符 "xxx"
String sql = "select TOP 7 news_id,news_title,news_addtime,news_url from web_news_info a" ...
- DEDECMS织梦自定义表单中必填项、电话邮箱过滤以及验证码规则
织梦自定义表单必填项规则--->(wwwshu-acca.com网站表单) 1. 在plus/diy.php 的第 40行下加如下代码: 1 2 3 4 5 6 7 8 9 10 11 12 1 ...
- Ubuntu安装mycli,让mysql命令行可以自动提示
安装mycli 1.确保有安装python 2.确保有安装pip 3.进入su模式,以管理员身份安装 4.安装 pip install -U mycli 5.登录 mycli -u root 很好很强 ...
- html5--6-28 css盒模型4
html5--6-28 css盒模型4 实例 学习要点 了解盒模型 元素内容.内边距.边框 和 外边距 了解盒模型的概念: CSS 盒模型规定了处理元素内容.内边距.边框 和 外边距 的方式. 最内部 ...
- SPOJ:Dandiya Night and Violence(Bitset优化)
It is Dandiya Night! A certain way how dandiya is played is described: There are N pairs of people p ...
- mack pro常用快捷键
fn + left / right / up / down 相当于 home/end/page up /page down delete 删除光标前一个字符 fn + delete 删除当前光标后一个 ...
- SKU的结构与页面渲染
http://blog.jobbole.com/109138/?lwfrom=user_dingfriend