题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1551

升级版:Uva 1471

题意:

  让你求删除一段连续的子序列之后的LIS。

题解:  

  预处理:先求一个last[i],以a[i]为开始的合法最长上升子序列的长度。再求一个pre[i],以a[i]为结尾的合法最长上升子序列长度。

  答案应该为

  max(以j结束的合法最长上升子序列长度) + 以a[i]为开始的合法最长上升子序列长度。 其中j<a[i]。

  1)通过树状数组维护区间最值。

  2)通过LIS 维护。(详细请看http://www.cnblogs.com/denghaiquan/p/6761600.html

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <sstream>
#include <algorithm>
using namespace std;
#define pb push_back
#define mp make_pair
#define ms(a, b) memset((a), (b), sizeof(a))
//#define LOCAL
#define eps 0.0000001
typedef long long LL;
const int inf = 0x3f3f3f3f;
const int maxn = +;
const int mod = ;
int a[maxn], pre[maxn], last[maxn], c[maxn];
int n;
int lowbit(int x){
return x&(-x);
}
int ask(int x)
{
int ans = ;
while(x>){
ans = max(ans, c[x]);
x-=lowbit(x);
}
return ans;
}
void updata(int x, int d)
{
while(x <= 1e4){
c[x] = max (c[x] , d);
x += lowbit(x);
}
}
void solve()
{
int ans = ;
ms(c, );
for(int i=;i<=n;i++) scanf("%d", &a[i]);
//last[i] 是第i个开始和合法后缀
last[n] = ;
for(int i = n-; i>;i--){
if(a[i] < a[i+]){
last[i] = last[i+] + ;
}else last[i] = ;
}
//pre[i] 是第i个结束的合法前缀
pre[] = ;
for(int i=;i<=n;i++){
if(a[i] > a[i-]){
pre[i] = pre[i-] + ;
}else pre[i] = ;
}
for(int i=;i<=n;i++){
ans = max(ans, last[i] + ask(a[i]-));
updata(a[i], pre[i]);
}
printf("%d\n", ans);
}
int main()
{
#ifdef LOCAL
freopen("jumping.in", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif // LOCAL
while(~scanf("%d", &n)){
solve();
}
return ;
}

升级版,应该数的范围在1e9所以无法用树状数组维护。只能用LIS或者set来维护。

CSU 1551 Longest Increasing Subsequence Again(树状数组 或者 LIS变形)的更多相关文章

  1. CSU - 1551 Longest Increasing Subsequence Again —— 线段树/树状数组 + 前缀和&后缀和

    题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1551 题意: 给出一段序列, 删除其中一段连续的子序列(或者不删), 使得剩下的序列 ...

  2. 【bzoj2225】[Spoj 2371]Another Longest Increasing CDQ分治+树状数组

    题目描述 给定N个数对(xi, yi),求最长上升子序列的长度.上升序列定义为{(xi, yi)}满足对i<j有xi<xj且yi<yj. 样例输入 8 1 3 3 2 1 1 4 5 ...

  3. csu 1551: Longest Increasing Subsequence Again BIT + 思维

    预处理last[i]表示以第i个开始,的合法后缀. pre[i]表示以第i个结尾,的合法前缀. 那么每一个数a[i],肯定是一个合法后缀last[i] + 一个合法前缀,那么合法前缀的数字要小于a[i ...

  4. CSUOJ 1551 Longest Increasing Subsequence Again

    1551: Longest Increasing Subsequence Again Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: 75  Solved ...

  5. HDU1087(树状数组求LIS)

    题是水题,学习一下用树状数组求LIS. 先离散化一下,注意去重:然后就把a[i]作为下标,dp[i]作为值,max作为维护的运算插进树状数组即可. 如果是上升子序列,询问(a[i] - 1):如果是不 ...

  6. Codeforces 946G Almost Increasing Array (树状数组优化DP)

    题目链接   Educational Codeforces Round 39 Problem G 题意  给定一个序列,求把他变成Almost Increasing Array需要改变的最小元素个数. ...

  7. HDU4991 Ordered Subsequence (树状数组优化DP)

    dp[i][j]表示以a[i]结尾的长度为j的上升子序列个数. 方程:dp[i][j]=sum(dp[k][j-1]),a[k]<a[i],1<=k<i. 求解目标:sum(dp[k ...

  8. Codeforces 486E LIS of Sequence --树状数组求LIS

    题意: 一个序列可能有多个最长子序列,现在问每个元素是以下三个种类的哪一类: 1.不属于任何一个最长子序列 2.属于其中某些但不是全部最长子序列 3.属于全部最长子序列 解法: 我们先求出dp1[i] ...

  9. poj1631——树状数组求LIS

    题目:http://poj.org/problem?id=1631 求LIS即可,我使用了树状数组. 代码如下: #include<iostream> #include<cstdio ...

随机推荐

  1. State Function Approximation: Linear Function

    In the previous posts, we use different techniques to build and keep updating State-Action tables. B ...

  2. OuterXml和InnerXml

    例如 <bkk> <rp fe="few" > <fe>fff</fe> </rp> </bkk> 对于fe ...

  3. java项目中,针对缓存问题的处理方式【接口中的处理方式】

    1.在service包中,分别建立了关于缓存的一系列的接口.类等,封装到一个工具包中: 临时缓存的接口(代码部分): package com.tools; import java.util.Date; ...

  4. ajax传文件用express的multer接住

    html部分: //input type设为file <input type="file" name="file" id="fileInputE ...

  5. HTTP协议详解??

    HTTP协议: HTTP (hypertext transport protocol) , 即 超 文 本 传 输 协 议 . 这 个 协 议 详 细 规 定 了 浏 览 器 和 万 维 网 服 务 ...

  6. Codeforces Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)

    传送门 A. XORinacci 手玩三四项发现序列就是 $a,b,a\ xor\ b,a,b,...$,直接输出即可 #include<iostream> #include<cst ...

  7. 关于html5 video的连续播放

    <!doctype html> <html lang="en"> <head> <meta charset="utf-8&quo ...

  8. fullpage.js版本3.0.5报错问题(licenseKey)

    在文件里搜索licenseKey,删除!不会对程序造成任何影响

  9. 构建LNMP+memcached服务

    通过PHP页面实现对memcached服务器的数据操作,实现以下目标: - 为PHP安装memcache扩展 - 创建PHP页面,并编写PHP代码,实现对memcached的数据操作 环境:部署LNM ...

  10. Mybatis中dao层实现

    在上一个笔记中继续: 因为要基于dao层,那么我们只需要又一个dao的接口,和一个mapper的文件就可以测试了. 但是基于dao层的时候需要规范: Mapper.xml文件中的namespace与m ...