HDU 5773 The All-purpose Zero
这题想了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的更多相关文章
- hdu 5773 The All-purpose Zero 最长上升子序列+树状数组
题目链接:hdu 5773 The All-purpose Zero 官方题解:0可以转化成任意整数,包括负数,显然求LIS时尽量把0都放进去必定是正确的. 因此我们可以把0拿出来,对剩下的做O(nl ...
- HDU 5773 The All-purpose Zero (变形LIS)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5773 0可以改变成任何数,问你严格递增的子序列最长是多少. 猜测0一定在最长上升子序列中用到,比如2 ...
- 【动态规划】【二分】【最长上升子序列】HDU 5773 The All-purpose Zero
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5773 题目大意: T组数据,n个数(n<=100000),求最长上升子序列长度(0可以替代任何 ...
- HDU 5773 The All-purpose Zero(树状数组)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5773 [题目大意] 给出一个非负整数序列,其中的0可以替换成任意整数,问替换后的最长严格上升序列长 ...
- hdu 5773 The All-purpose Zero 线段树 dp
The All-purpose Zero 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5773 Description ?? gets an seq ...
- HDU 5773 The All-purpose Zero(O(nlgn)求LIS)
http://acm.hdu.edu.cn/showproblem.php?pid=5773 题意: 求LIS,其中的0可以看做任何数. 思路: 因为0可以看做任何数,所以我们可以先不管0,先求一遍L ...
- HDU 5773:The All-purpose Zero(贪心+LIS)
http://acm.hdu.edu.cn/showproblem.php?pid=5773 The All-purpose Zero Problem Description ?? gets an ...
- HDU 5773 最长上升子序列
题意 给出一个序列 问它的最长严格上升子序列多长 这个序列中的0可以被替代为任何数 n的范围给出了1e5 所以平常的O(n*n)lis不能用了 在kuangbin的模板里有O(nlogn)的模板 套上 ...
- 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]) 用二分可以 ...
随机推荐
- Java之IO流
目录: 1.文件编码 2.File类 3.RandomAccessFile 4.字节流 5.字符流 6.对象的序列化和反序列化 1.文件编码 1)相关知识点 八进制和十六进制的表示方式:八进制前面加0 ...
- for i in xrange(0,5)使用过程中遇到的问题
文件中共有4行内容. fd = open("C:\Users\william\Desktop\dup_file - Copy (2).txt")for i in xrange(0, ...
- Quartz的cron表达式
一个cron表达式有至少6个(也可能7个)有空格分隔的时间元素. 按顺序依次为 秒(0~59) 分钟(0~59) 小时(0~23) 天(月)(0~31,但是你需要考虑你月的天数) 月(0~11) 天( ...
- 用perl发送数据到钓鱼站
一个皮皮果的游戏很火 估计很多人想黑 偶然发现一个钓鱼站: http://ppgpergame.com/ 钓用户名与密码 抓包后发现数据会发送到: http://ppgpergame.com/db.a ...
- MySQL的保留关键字,使用时尽量避免
今天用phpmyadmin时,注意到一个提示: 列名 'update' 是一个MySQL 保留关键字. 突然意识到还是应该尽量避免这些保留关键字,也百度了一下.找到了这些关键字,列出来下 使用mysq ...
- PHP面向对象编程 对象的基本概念 PHP面向对象的基本实践 PHP面向对象的高级实践 PHP面向对象的特殊实践
再次梳理一下面向对象编程的要点. 此文是以php为例,但思想是通用的. 总结的PHP面向对象编程笔记 对象的基本概念 对象的基本构成 对象包含两部分 一.对象的组成元素 是对象的数据模型,用于描述对象 ...
- Restaurant & Cooking Starter Kit v1.2.1
项目: using UnityEngine; using System.Collections; namespace VoidGame { public class Constant : MonoBe ...
- 回滚 rollback
为了保证在应用程序.数据库或系统出现错误后,数据库能够被还原,以保证数据库的完整性,所以需要进行回滚. 回滚(rollback)就是在事务提交之前将数据库数据恢复到事务修改之前数据库数据状态. 回滚执 ...
- Windows下WordPress搭建博客过程
搭建环境:Win7 + XAMPP5.5 + wordpress4.5.1 官网下载安装包,解压,拷贝到网站根目录(D:\IT\XAMPP5.5\htdocs\),重命名为blog(随意) 创建数据库 ...
- openstack私有云布署实践【4.1 上层代理haproxy配置 (科兴环境)】
官方文档上的高可用配置,它推荐的是使用haproxy的上层代理来实现服务组件的主备访问.或者负载均衡访问 一开始我也是使用haproxy来做的,但后来方式改了 测试环境:haproxy + n ...