题意:

给一个长度为\(N\)的序列,要删除一段长为\(L\)的连续子序列,问所能得到的最长的\(LIS\)的长度。

分析:

设\(f(i)\)表示以\(a_i\)结尾的\(LIS\)的长度,设\(g(i)\)表示以\(a_i\)结尾而且被删去一段长为\(L\)的\(LIS\)的长度。

则有状态转移方程:

\(g(i)=max( g(j) , f(j)_{j<i-L} )\)

用树状数组维护一下。

我用二分也写了一遍,WA掉了,不知道怎么改。 = =||

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; const int maxn = 100000 + 10; int n, L; int a[maxn], b[maxn]; int f[maxn], g[maxn]; int C1[maxn], C2[maxn]; inline int lowbit(int x) { return x & (-x); } void Change(int* C, int x, int v) {
while(x <= n) {
C[x] = max(C[x], v);
x += lowbit(x);
}
} int Query(int* C, int x) {
int ans = 0;
while(x) {
ans = max(ans, C[x]);
x -= lowbit(x);
}
return ans;
} int main() {
//freopen("in.txt", "r", stdin); int T; scanf("%d", &T);
for(int kase = 1; kase <= T; kase++) {
scanf("%d%d", &n, &L);
for(int i = 1; i <= n; i++) {
scanf("%d", a + i);
b[i] = a[i];
}
sort(b + 1, b + 1 + n);
for(int i = 1; i <= n; i++) a[i] = lower_bound(b + 1, b + 1 + n, a[i]) - b; memset(f, 0, sizeof(f));
memset(g, 0, sizeof(g));
memset(C1, 0, sizeof(C1));
memset(C2, 0, sizeof(C2)); int ans = 0;
for(int i = L + 1; i <= n; i++) {
g[i] = max(Query(C1, a[i] - 1), Query(C2, a[i] - 1)) + 1;
ans = max(ans, g[i]);
Change(C2, a[i], g[i]);
f[i - L] = Query(C1, a[i - L] - 1) + 1;
Change(C1, a[i - L], f[i - L]);
}
ans = max(ans, f[n - L]); //可能是去掉最后L个 printf("Case #%d: %d\n", kase, ans);
} return 0;
}

HDU 5489 Removed Interval DP 树状数组的更多相关文章

  1. HDU 2836 Traversal 简单DP + 树状数组

    题意:给你一个序列,问相邻两数高度差绝对值小于等于H的子序列有多少个. dp[i]表示以i为结尾的子序列有多少,易知状态转移方程为:dp[i] = sum( dp[j] ) + 1;( abs( he ...

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

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

  3. 树形DP+树状数组 HDU 5877 Weak Pair

    //树形DP+树状数组 HDU 5877 Weak Pair // 思路:用树状数组每次加k/a[i],每个节点ans+=Sum(a[i]) 表示每次加大于等于a[i]的值 // 这道题要离散化 #i ...

  4. bzoj 1264 [AHOI2006]基因匹配Match(DP+树状数组)

    1264: [AHOI2006]基因匹配Match Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 793  Solved: 503[Submit][S ...

  5. HDU 5862 Counting Intersections(离散化+树状数组)

    HDU 5862 Counting Intersections(离散化+树状数组) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 D ...

  6. hdu 5517 Triple(二维树状数组)

    Triple Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Sub ...

  7. 【bzoj2274】[Usaco2011 Feb]Generic Cow Protests dp+树状数组

    题目描述 Farmer John's N (1 <= N <= 100,000) cows are lined up in a row andnumbered 1..N. The cows ...

  8. 奶牛抗议 DP 树状数组

    奶牛抗议 DP 树状数组 USACO的题太猛了 容易想到\(DP\),设\(f[i]\)表示为在第\(i\)位时方案数,转移方程: \[ f[i]=\sum f[j]\;(j< i,sum[i] ...

  9. HDU 2227 Find the nondecreasing subsequences (DP+树状数组+离散化)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2227 Find the nondecreasing subsequences             ...

随机推荐

  1. Mvc异常处理器

    using System; using System.Text; using EMS.Domains.Core; using System.Web.Mvc; using Json.Net; using ...

  2. I/O————流

    流的关系图 缓冲流分为字节和字符缓冲流(图中是经常用的搭配,PrintWrite与BufferedWrite都继承java.io.Write) 字节缓冲流为: BufferedInputStream— ...

  3. TCP的三次握手以及TCP状态转换图详解

    今天来讨论一下TCP的三次握手以及TCP的状态转换图.首先发一个三次握手的流程图如下: 圖 2.4-3.三向交握之封包连接模式A:封包发起当用戶端想要对服务器端发起连接时,就必須要送出一個要求连线的封 ...

  4. Ubuntu 设置静态ip地址

    1. 找到文件并作如下修改: sudo vim /etc/network/interfaces 修改如下部分: auto eth0iface eth0 inet staticaddress 192.1 ...

  5. Hadoop 2.7.0模拟分布式实验环境搭建[亲测]

    实验目的: 本实验通过在PC电脑上同时运行3个虚拟机,一个为master节点,两个slave节点.    搭建环境: 主机:mac os 10.10   OS:CenOS 6.5 虚拟机:VMware ...

  6. 首次将项目从svn下载到eclipse

    1.点击 File --> Import,进入导入项目窗口 2.选择从SVN检出项目,点击Next 3.选择创建新的资源库位置,点击Next 4.在URL处输入SVN项目远程地址,点击Next ...

  7. Python使用easy-install安装时报UnicodeDecodeError的解决方法

    Python使用easy-install安装时报UnicodeDecodeError的解决方法,有需要的朋友可以参考下. 问题描述: 在使用easy-install安装matplotlib.pypar ...

  8. pod install Pull is not possible because you have unmerged files.

    http://stackoverflow.com/questions/21474536/podfile-gives-an-error-on-install A bug was found in lib ...

  9. python3.6 配置COCO API出错解决方案

    使用Anaconda Prompt进行安装 问题出现的背景:在尝试使用mask-rcnn时,遇到了这个问题,最终解决掉了

  10. 剑指offer24 二叉搜索树的后序遍历序列

    自己写的更简洁的代码 class Solution { public: bool VerifySquenceOfBST(vector<int> sequence) { int length ...