题目链接: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. PL/SQL Developer 报错Dynamic Performance Tables not accessible, Automatic Statistics disabled for this session You can disable statistics in the preference menu, or obtain select priviliges on the V$ses

    可以从以下几个方面考虑: 1)单独给用户授动态性能视图的权限: SQL> grant select on V_session  to user; SQL> grant select on  ...

  2. 关于NewJson dll 引用不一致

    {System.IO.FileLoadException: 未能加载文件或程序集“Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKe ...

  3. Java相关面试题总结+答案(九)

    [MySQL] 164. 数据库的三范式是什么? 第一范式:强调的是列的原子性,即数据库表的每一列都是不可分割的原子数据项. 第二范式:属性完全依赖于主键(满足第一范式的前提下),即任意一个字段只依赖 ...

  4. CentOS7 修复boot目录

    这里为了达到实验目的,首先删除boot目录下所有内容 重启后发现系统进不去了,这正是我们想要的 进入系统救援模式,以重新引导系统 进入救援模式后,输入以下命令进行修复boot目录 重启后,能正常引导系 ...

  5. Snacks HDU 5692 dfs序列+线段树

    Snacks HDU 5692 dfs序列+线段树 题意 百度科技园内有n个零食机,零食机之间通过n−1条路相互连通.每个零食机都有一个值v,表示为小度熊提供零食的价值. 由于零食被频繁的消耗和补充, ...

  6. 树莓派上编译安装python3.6

    1.更新树莓派系统 sudo apt-get update sudo apt-get upgrade -y 2.安装python依赖环境 sudo apt-get install build-esse ...

  7. VINS 估计器之外参初始化

    为何初始化外参 当外参完全不知道的时候,VINS也可以在线对其进行估计(rotation),先在processImage内进行初步估计,然后在后续优化时,会在optimize函数中再次优化. 如何初始 ...

  8. java.lang.NoClassDefFoundError: javax/transaction/Synchronization

    转自:https://blog.csdn.net/andsionok/article/details/68490848 今天在整合ssh框架中 程序报告Java.lang.NoClassDefFoun ...

  9. selenium下拉菜单

    from selenium.webdriver.support.select import Selectdef select_value(self, css, value):    '''    选中 ...

  10. 12 | 为什么我的MySQL会“抖”一下? 学习记录

    <MySQL实战45讲>12 | 为什么我的MySQL会“抖”一下? 学习记录 http://naotu.baidu.com/file/15aa54cab2fa882c6a2a1dd52e ...