AC日记——[HNOI2008]玩具装箱toy bzoj 1010
思路:
斜率优化DP;
代码:
#include <bits/stdc++.h>
using namespace std;
#define maxn 50005
#define ll long long
ll que[maxn],sum[maxn],dp[maxn],n,l,ai[maxn],a;
inline void in(ll &now)
{
char Cget=getchar();now=;
while(Cget>''||Cget<'')Cget=getchar();
while(Cget>=''&&Cget<='')
{
now=now*+Cget-'';
Cget=getchar();
}
}
ll G(ll now)
{
return sum[now]+now;
}
ll Y(ll x,ll y)
{
return dp[x]+pow(G(x)+a,)-dp[y]-pow(G(y)+a,);
}
ll X(ll x,ll y)
{
return *(G(x)-G(y));
}
int main()
{
in(n),in(l),a=l+;ll h=,tail=;
for(ll i=;i<=n;i++) in(ai[i]),sum[i]=sum[i-]+ai[i];
for(ll i=;i<=n;i++)
{
while(h<tail&&Y(que[h+],que[h])<=G(i)*X(que[h+],que[h])) ++h;
dp[i]=dp[que[h]]+(G(i)-G(que[h])-a)*(G(i)-G(que[h])-a);
while(h<tail&&Y(i,que[tail])*X(que[tail],que[tail-])<=Y(que[tail],que[tail-])*X(i,que[tail])) --tail;
que[++tail]=i;
}
cout<<dp[n];
return ;
}
AC日记——[HNOI2008]玩具装箱toy bzoj 1010的更多相关文章
- 【BZOJ 1010】 [HNOI2008]玩具装箱toy (斜率优化)
1010: [HNOI2008]玩具装箱toy Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 9330 Solved: 3739 Descriptio ...
- bzoj 1010 [HNOI2008]玩具装箱toy(DP的斜率优化)
1010: [HNOI2008]玩具装箱toy Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 7874 Solved: 3047[Submit][St ...
- BZOJ 1010: [HNOI2008]玩具装箱toy [DP 斜率优化]
1010: [HNOI2008]玩具装箱toy Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 9812 Solved: 3978[Submit][St ...
- BZOJ 1010: [HNOI2008]玩具装箱toy 斜率优化DP
1010: [HNOI2008]玩具装箱toy Description P教授要去看奥运,但是他舍不下他的玩具,于是他决定把所有的玩具运到北京.他使用自己的压缩器进行压缩,其可以将任意物品变成一堆,再 ...
- BZOJ 1010 [HNOI2008]玩具装箱toy
1010: [HNOI2008]玩具装箱toy Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 7184 Solved: 2724[Submit][St ...
- Bzoj 1010: [HNOI2008]玩具装箱toy(斜率优化)
1010: [HNOI2008]玩具装箱toy Time Limit: 1 Sec Memory Limit: 162 MB Description P教授要去看奥运,但是他舍不下他的玩具,于是他决定 ...
- BZOJ 1010: [HNOI2008]玩具装箱toy(DP+斜率优化)
[HNOI2008]玩具装箱toy Description P教授要去看奥运,但是他舍不下他的玩具,于是他决定把所有的玩具运到北京.他使用自己的压缩器进行压缩,其可以将任意物品变成一堆,再放到一种特殊 ...
- 1010: [HNOI2008]玩具装箱toy(斜率优化)
1010: [HNOI2008]玩具装箱toy Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 12280 Solved: 5277[Submit][S ...
- 【bzoj1010】[HNOI2008]玩具装箱toy
1010: [HNOI2008]玩具装箱toy Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 9281 Solved: 3719[Submit][St ...
随机推荐
- 第九章 C99可变长数组VLA详解
C90及C++的数组对象定义是静态联编的,在编译期就必须给定对象的完整信息.但在程序设计过程中,我们常常遇到需要根据上下文环境来定义数组的情况,在运行期才能确知数组的长度.对于这种情况,C90及C++ ...
- Atlantis HDU - 1542 (线段树扫描线)
There are several ancient Greek texts that contain descriptions of the fabled island Atlantis. Some ...
- ACM2112迪克斯特算法
HDU Today Problem Description 经过锦囊相助,海东集团终于度过了危机,从此,HDU的发展就一直顺风顺水,到了2050年,集团已经相当规模了,据说进入了钱江肉丝经济开发区50 ...
- jq 由name获取那个radio选中了的
$("input[name='approve']:checked").val() //获取radio选中的值;var radio_checked_val = $("#fo ...
- python 面试题(1)
好用简洁的大数据技术:python.hadoop.R 慢慢学习,随时分享 1.什么是Python?使用Python有什么好处? Python是一种编程语言,它有对象.模块.线程.异常处理和自动内存管理 ...
- jenkins修改job默认名字
${GIT_BRANCH,fullName="false"}-${BUILD_NUMBER}-${GIT_REVISION,length=12}-${deploy_rollback ...
- C# 从串口读取数据
最近要做系统集成,需要从串口读取数据,随学习一下相关知识: 以下是从串口读取数据 public static void Main() { SerialPort mySerialPort = new S ...
- 【BZOJ4837】LRU算法 [模拟]
LRU算法 Time Limit: 6 Sec Memory Limit: 128 MB[Submit][Status][Discuss] Description 小Q同学在学习操作系统中内存管理的 ...
- UIActivityIndicatorView---iOS-Apple苹果官方文档翻译
本系列所有开发文档翻译链接地址: iOS7开发-Apple苹果iPhone开发Xcode官方文档翻译PDF下载地址 UIActivityIndicatorViewactivityIndicatorVi ...
- perl6中函数参数(2)
use v6; #如果参数是可选的, 可以在后面加个?后定义 sub Choo($x, $y?){ say $x+$y; } Choo(); Choo(,); #具名参数, 也就是字典形式的调用 su ...