这题想了1个多小时想不出来...方法真是精妙...

官方题解:0可以转化成任意整数,包括负数,显然求LIS时尽量把0都放进去必定是正确的。因此我们可以把0拿出来,对剩下 的做O(nlogn)的LIS,统计结果的时候再算上0的数量。为了保证严格递增,我们可以将每个权值S[i]减去i前面0的个 数,再做LIS,就能保证结果是严格递增的。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
inline int read()
{
char c = getchar(); while(!isdigit(c)) c = getchar();
int x = ;
while(isdigit(c)) { x = x * + c - ''; c = getchar(); }
return x;
} const int maxn=+;
int T,n,a[maxn],sum[maxn],dp[maxn];
int t[*maxn]; void update(int p,int val,int l,int r,int rt)
{
if(l==r) { t[rt]=max(val,t[rt]); return; } int m=(l+r)/;
if(p<=m) update(p,val,l,m,*rt); else update(p,val,m+,r,*rt+);
t[rt]=max(t[*rt],t[*rt+]);
} int get(int L,int R,int l,int r,int rt)
{
if(L<=l&&r<=R) return t[rt]; int m=(l+r)/,maxL=,maxR=;
if(L<=m) maxL=get(L,R,l,m,*rt); if(R>m) maxR=get(L,R,m+,r,*rt+);
return max(maxL,maxR);
} int main()
{
scanf("%d",&T); int cas=;
while(T--)
{
memset(dp,,sizeof dp); memset(sum,,sizeof sum); memset(t,,sizeof t);
scanf("%d",&n); for(int i=;i<=n;i++) scanf("%d",&a[i]);
for(int i=;i<=n;i++) { sum[i]=sum[i-]; if(a[i]==) sum[i]++; } for(int i=;i<=n;i++)
{
if(a[i]==) continue;
a[i]=a[i]-sum[i]+;
if(a[i]!=) dp[i]=get(,a[i]-,,,)+; else dp[i]=;
update(a[i],dp[i],,,);
}
int Max=; for(int i=;i<=n;i++) Max=max(Max,dp[i]);
printf("Case #%d: %d\n",cas++,Max+sum[n]);
}
return ;
}

HDU 5773 The All-purpose Zero的更多相关文章

  1. hdu 5773 The All-purpose Zero 最长上升子序列+树状数组

    题目链接:hdu 5773 The All-purpose Zero 官方题解:0可以转化成任意整数,包括负数,显然求LIS时尽量把0都放进去必定是正确的. 因此我们可以把0拿出来,对剩下的做O(nl ...

  2. HDU 5773 The All-purpose Zero (变形LIS)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5773 0可以改变成任何数,问你严格递增的子序列最长是多少. 猜测0一定在最长上升子序列中用到,比如2 ...

  3. 【动态规划】【二分】【最长上升子序列】HDU 5773 The All-purpose Zero

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5773 题目大意: T组数据,n个数(n<=100000),求最长上升子序列长度(0可以替代任何 ...

  4. HDU 5773 The All-purpose Zero(树状数组)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5773 [题目大意] 给出一个非负整数序列,其中的0可以替换成任意整数,问替换后的最长严格上升序列长 ...

  5. hdu 5773 The All-purpose Zero 线段树 dp

    The All-purpose Zero 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5773 Description ?? gets an seq ...

  6. HDU 5773 The All-purpose Zero(O(nlgn)求LIS)

    http://acm.hdu.edu.cn/showproblem.php?pid=5773 题意: 求LIS,其中的0可以看做任何数. 思路: 因为0可以看做任何数,所以我们可以先不管0,先求一遍L ...

  7. HDU 5773:The All-purpose Zero(贪心+LIS)

    http://acm.hdu.edu.cn/showproblem.php?pid=5773 The All-purpose Zero Problem Description   ?? gets an ...

  8. HDU 5773 最长上升子序列

    题意 给出一个序列 问它的最长严格上升子序列多长 这个序列中的0可以被替代为任何数 n的范围给出了1e5 所以平常的O(n*n)lis不能用了 在kuangbin的模板里有O(nlogn)的模板 套上 ...

  9. HDU 5773 The All-purpose Zero 求LIS

    求最长上升子序列长度: 单纯的dp时间复杂度是O(n*n)的 dp[i] = max(dp[j]+1); (0=<j<=i-1 && a[i]>a[j]) 用二分可以 ...

随机推荐

  1. sudo密码错误的解决办法

    按一下Caps Lock键,如果大写灯亮了,再按一下. 然后重新输入sudo密码,尝试.

  2. Javascript Date 判断输入日期是否正确

    JavaScript的Date对象有容错性,可将随意给定的日期的年月日自动生成正确的日期时间 //JavaScript中Date对象容错性 function dateCheck(){ var date ...

  3. re2c实例

    #include <stdio.h> #include "demo_def.h" #define T_BEGIN 0 #define T_NUMBER 1 #defin ...

  4. for i in xrange(0,5)使用过程中遇到的问题

    文件中共有4行内容. fd = open("C:\Users\william\Desktop\dup_file - Copy (2).txt")for i in xrange(0, ...

  5. google浏览器图标显示不正常怎么办

    taskkill /f /im explorer.exe rem 清理系统图标缓存数据库 attrib -h -s -r "%userprofile%\AppData\Local\IconC ...

  6. Python朝花夕拾

    Q1:HTTP Error 403: Forbidden python中经常使用urllib2.urlopen函数提取网页源码,但是有些时候这个函数返回的却是:HTTP Error 403: Forb ...

  7. CBC之php java兼容版本

    网上搜了N多代码,都是你抄我的,我抄你的,着实让人无语对苍天.经过多番资料的查找,php与java的cbc加密.解密结果终于一致了,代码如下: Java加密解密类: package main; imp ...

  8. Java AOP - Aspectj

    1. 序 Aspect Oriented Programming (AOP)是近来一个比较热门的话题. AspectJ是AOP的Java语言的实现,获得了Java程序员的广泛关注. 关于AspectJ ...

  9. MySQL备份参数详解

    mysqldump 是采用SQL级别的备份机制,它将数据表导成 SQL 脚本文件,在不同的 MySQL 版本之间升级时相对比较合适,这也是最常用的备份方法. 1. --compatible = nam ...

  10. zoj 2750 Idiomatic Phrases Game

    迪杰斯特拉单源最短路算法.对成语进行预处理.做出邻接矩阵即可. #include<cstdio> #include<cstring> #include<cmath> ...