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]) 用二分可以 ...
随机推荐
- C#模板打印功能-模板为WPS或Excel
//---WPS----- using EtApp = ET; using System.Reflection; using System.Runtime.InteropServices; using ...
- MYSQL 主从复制(NIOT)
一.主数据库操作设置(A) 1.修改配置文件,vim /etc/my.cnf,然后重启mysqld,/etc/init.d/mysqld restart [mysqld]<要在mysqld中括号 ...
- 找轮转后的有序数组中第K小的数
我们可以通过二分查找法,在log(n)的时间内找到最小数的在数组中的位置,然后通过偏移来快速定位任意第K个数. 此处假设数组中没有相同的数,原排列顺序是递增排列. 在轮转后的有序数组中查找最小数的算法 ...
- LDAP协议
很多人虽然会使用dsadd等命令添加用户,但是dsadd的命令说明里面并没有涉及到dc,cn,ou的含义,很多人都不明白,这里是微软的技术支持人 员的回信,希望对大家有帮助. CN, OU, DC 都 ...
- ZZNU 1995: cots' times
题目描述 XX年XX月XX日小cot学会了回文数,eg:121. 小cot上课容易走神, 经常看看这个,瞧瞧那个.在小cot某一次走神的过程中他发现电子表上的时间也有回文数... 当然,并不是每次走神 ...
- 在Ubuntu 14.04安装 Let’s Encrypt并配置ssl
1.下载安装 Let's Encrypt客户端 cd /usr/local/sbin sudo wget https://dl.eff.org/certbot-auto 2.添加执行权限 sudo c ...
- ACdream 1028 Path
先思考一下序列上应该怎么做. 如果某段和为x,并且x为偶数,那么比x小的偶数,一定是这段的子段. 如果某段和为x,并且x为奇数,那么比x小的奇数,一定是这段的子段. 因此....只要寻找最大的连续的和 ...
- bootstrap复习:组件
一.下拉菜单 1.实例:将下拉菜单触发器和下拉菜单都包裹在 .dropdown 里,或者另一个声明了 position: relative; 的元素.然后加入组成菜单的 HTML 代码.为下拉菜单的父 ...
- Java 泛型 泛型代码和虚拟机
Java 泛型 泛型代码和虚拟机 @author ixenos 类型擦除.原始类型.给JVM的指令.桥方法.Java泛型转换的事实 l 类型擦除(type erasure) n Java泛型的处理 ...
- 浙大pat 1037
1037. Magic Coupon (25) 时间限制 100 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The magi ...