HDU 5489 Removed Interval
题意:求一段序列中删掉L个连续元素后的LIS。
解法:我的想法很复杂= =怎么说呢……首先用nlogn的方法求LIS得到的序列dp的第i项的意义为上升子序列所有长度为i的序列结尾元素的最小值,那么先倒着用nlogn的方法求一遍最长下降子序列记为dp1,记录每一步怎么更新的dp1,再正着求一遍最长上升子序列,每次看a[i]的时候二分的在i+k到结尾的dp1中找第一个比a[i]大的数设为dp1[pos],所以当前枚举的答案即为以a[i]作为结尾的最长上升子序列+后一段以dp1[pos]开头的最长上升子序列……枚举1~n-l,就可以得到答案了TUT……
总之很艰辛……二分废又得找队友帮忙手写二分什么的……
另一队的人提出用线段树算LIS……真·大神= =不懂怎么转移的方程……
代码:
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<limits.h>
#include<time.h>
#include<stdlib.h>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#define LL long long
int inf = 1000000005;
using namespace std;
int a[100005];
LL dp1[100005], dp2[100005];
struct node
{
bool isnew;
int pos;
int pre;
}note[100005];
bool cmp(int a, int b)
{
return a > b;
}
template <class T>
int rupper_bound(T *a, T *end, T key) {
int n = end - a;
if(n == 0) return INT_MAX;
if (a[n-1] > key) return n-1;
if (a[0] <= key) return INT_MAX;
int l = 0, r = n - 1;
while(r - l > 1) {
int m = (l+r) >> 1;
if (a[m] > key) l = m;
else r = m;
}
return l;
}
int main()
{
int T;
scanf("%d", &T);
int cse = 1;
while(T--)
{
int n, l;
scanf("%d%d", &n, &l);
for(int i = 1; i <= n; i++)
scanf("%d", &a[i]);
a[0] = -inf;
int max1 = 0, max2 = 0;
for(int i = n; i > l; i--)
{
int pos = upper_bound(dp1, dp1 + max1, a[i], cmp) - dp1;
if(pos == max1)
{
note[i].isnew = 1;
note[i].pos = max1;
dp1[max1++] = a[i];
}
else
{
note[i].isnew = 0;
note[i].pos = pos;
note[i].pre = dp1[pos];
dp1[pos] = a[i];
}
}
int ans = 0;
LL s = -inf;
int len = 0;
for(int i = 1; i <= n - l + 1; i++)
{
int pos = rupper_bound(dp1, dp1 + max1, s);
if(pos == INT_MAX) ans = max(ans, len);
else ans = max(ans, pos + 1 + len);
int x = upper_bound(dp2, dp2 + max2, a[i]) - dp2;
if(x == max2)
{
len = max2 + 1;
s = a[i];
dp2[max2++] = a[i];
}
else
{
len = x + 1;
s = a[i];
dp2[x] = a[i];
}
if(note[i + l].isnew)
{
max1--;
}
else
{
dp1[note[i + l].pos] = note[i + l].pre;
}
}
printf("Case #%d: %d\n", cse++, ans);
}
return 0;
}
HDU 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 (2015 ACM/ICPC Asia Regional Hefei Online)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5489 题目大意: 一个N(N<=100000)个数的序列,要从中去掉相邻的L个数(去掉整个区间 ...
- 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 DP 树状数组
题意: 给一个长度为\(N\)的序列,要删除一段长为\(L\)的连续子序列,问所能得到的最长的\(LIS\)的长度. 分析: 设\(f(i)\)表示以\(a_i\)结尾的\(LIS\)的长度,设\(g ...
- 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颗树状数组.. 比赛的时候一句话位置写错了,然 ...
随机推荐
- **PHP随机数算法
<?php $tmp = range(1,30);print_r(array_rand($tmp,10));?> 输出: Array( [0] => 6 [1] => 8 [2 ...
- hdu 1755 A Number Puzzle
这题枚举k节省时间 ;}
- MQTT客户端与服务代理的案列
服务端,采用 Mosquitto 来转发分发消息. 客户端自己写. 服务端 启动 mosquitto (底下的命令是我自己放到环境变量里面的,通过alias 运行mosquitto) Ishallbe ...
- Minimum_Window_Substring两种方法求解
题目描述: Given a string S and a string T, find the minimum window in S which will contain all the chara ...
- 卓京---java基础2
2.数据类型 基本类型: 整型: byte字节型 8位(bit) -2^7~2^7-1(-128~127) 0000 0000 short短整型 16位 -2^15~2^15-1(-32768 ...
- 62. Unique Paths
题目: A robot is located at the top-left corner of a m x ngrid (marked 'Start' in the diagram below). ...
- Linux批量杀进程
ps -ef |grep 进程名|grep -v grep |awk '{print $2}' |xargs kill -9
- VS2012 开发SharePoint 2013 声明式workflow action(activity)之 HelloWorld
本文讲述VS2012 开发SharePoint 2013 声明式workflow action 之 HelloWorld. 使用VS2012开发客户化的workflow action是SharePoi ...
- xmlsechema验证
//创建xmlDocument XmlDocument doc = new XmlDocument(); ...
- 【Latex】如何在Latex中插入伪代码 —— clrscode3e
1. 简介clrscode3e是<算法导论(第三版)>使用的伪代码的宏包,clrs其实表示的是Cormen.Leiserson.Rivest和Stein.它有个更老的版本clrscode, ...