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]) 用二分可以 ...
随机推荐
- Spring mail 邮件发送的简单实现
package cn.taskSys.utils; import java.util.Properties; import org.springframework.mail.MailException ...
- 在线预览pdf、xlsx、docx、ppt等文档
使用微软提供的Office Online平台只需要一个网址即可在线查看Xls,doc,PPT等文档 http://view.officeapps.live.com/op/view.aspx?src=要 ...
- JAVA多态问题总结(课堂总结)
面向对象的三大特性:封装.继承.多态.从一定角度来看,封装和继承几乎都是为多态而准备的.这是我们最后一个概念,也是最重要的知识点.多态的定义:指允许不同类的对象对同一消息做出响应.即同一消息可以根据发 ...
- npm 使用代理
npm install 有时候会安装失败,可能是网络的问题,可以使用代理来安装 npm获取配置有6种方式,优先级由高到底. 命令行参数. --proxy http://server:port即将pro ...
- nginx读取图片没有权限
场景是这样的,我们项目中上传图片到linux服务器后,保存图片存储路径和网络访问路径.app中用数据库返回的 图片访问路径来访问图片(nginx通过nfs方式读取图片).但是访问不到.要手动 chmo ...
- 通过this获取当前点击选项相关数据
很多时候jquery只能或者应该回去一个集合.然后通过this获取触发时间的对象及相关属性 this.jq('#needsType').on("click", ".sel ...
- linux deepin 12.12.1和Windows 7双系统修改默认启动项
1.打开终端,输入 sudo gedit /etc/default/grub ,然后输入密码.2.在出来的文本编辑器中找到 GRUB_DEFAULT=0 一行,把0改为2(因为我的Windows 7在 ...
- Struts入门学习(一)
刚开始学习框架的时候感觉很简单,都是用到javaEE的相关框架,自己就想研究源码,但是学了很久之后毫无头绪,所以还是扎扎实实学好Struts毕竟框架做起来要比自己写javaEE要简单,下面我们就来一步 ...
- jQuery实例1
1.选择器: <body> <script src="jquery-2.2.4.js"></script> <div id="n ...
- GLSL 纹理贴图
#include <ork/render/FrameBuffer.h> #include <ork/scenegraph/SceneManager.h> #include &l ...