1010 [HNOI2008]玩具装箱toy
斜率优化dp;
推荐学习http://www.cnblogs.com/perseawe/archive/2012/05/12/bz1010.html
看着别人的题解自己学着推,终于理解了
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
#define maxn 50005
using namespace std; int q[maxn],head=,tail=;
ll f[maxn];
ll g[maxn],s[maxn];
ll dp[maxn]; ll get_g(int k,int j,int c)
{
return dp[k]+(f[k]+c)*(f[k]+c)-dp[j]-(f[j]+c)*(f[j]+c);
} ll get_s(int k,int j)
{
return *(f[k]-f[j]);
} int main()
{
int n,m,xx;
scanf("%d%d",&n,&m);
for(int i=; i<=n; i++)
{
scanf("%d",&xx);
f[i]+=f[i-]+xx;
}
for(int i=; i<=n; i++)f[i]+=i;
int c=+m;
q[tail++]=;
for(int i=;i<=n;i++)
{
while(head<tail-&&get_g(q[head+],q[head],c)<=f[i]*get_s(q[head+],q[head]))++head;
int v=q[head];
dp[i]=dp[v]+(f[i]-f[v]-c)*(f[i]-f[v]-c);
q[tail++]=i;
for(int j=tail-;j>head;j--)
{
int cc=q[j+];
int bb=q[j];
int aa=q[j-];
if(get_g(bb,aa,c)*get_s(cc,bb)>=get_g(cc,bb,c)*get_s(bb,aa))
q[j]=q[--tail];
else break;
}
}
printf("%lld\n",dp[n]);
return ;
}
1010 [HNOI2008]玩具装箱toy的更多相关文章
- 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(DP的斜率优化)
1010: [HNOI2008]玩具装箱toy Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 7874 Solved: 3047[Submit][St ...
- BZOJ 1010 [HNOI2008]玩具装箱toy
1010: [HNOI2008]玩具装箱toy Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 7184 Solved: 2724[Submit][St ...
- 1010: [HNOI2008]玩具装箱toy(斜率优化)
1010: [HNOI2008]玩具装箱toy Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 12280 Solved: 5277[Submit][S ...
- Bzoj 1010: [HNOI2008]玩具装箱toy(斜率优化)
1010: [HNOI2008]玩具装箱toy Time Limit: 1 Sec Memory Limit: 162 MB Description P教授要去看奥运,但是他舍不下他的玩具,于是他决定 ...
- BZOJ 1010: [HNOI2008]玩具装箱toy(斜率优化dp)
http://www.lydsy.com/JudgeOnline/problem.php?id=1010 题意: 思路: 容易得到朴素的递归方程:$dp(i)=min(dp(i),dp(k)+(i-k ...
- 【BZOJ】1010: [HNOI2008]玩具装箱toy(dp+斜率优化)
http://www.lydsy.com/JudgeOnline/problem.php?id=1010 蛋疼用latex写了份题解.. 2015.03.07 upd:很多东西可能有问题,最好看下边提 ...
- 1010: [HNOI2008]玩具装箱toy [dp][斜率优化]
Description P教授要去看奥运,但是他舍不下他的玩具,于是他决定把所有的玩具运到北京.他使用自己的压缩器进行压缩,其可以将任意物品变成一堆,再放到一种特殊的一维容器中.P教授有编号为1... ...
- BZOJ 1010: [HNOI2008]玩具装箱toy | 单调队列优化DP
原题: http://www.lydsy.com/JudgeOnline/problem.php?id=1010 题解: #include<cstdio> #include<algo ...
随机推荐
- 为ubuntu只带的network-manager添加latp/ipsec VPN
sudo apt-add-repository ppa:seriy-pr/network-manager-l2tp sudo apt-get update sudo apt-get install n ...
- [转载]Ubuntu 14.04设置固定ip
参考链接: ubuntu14.04设置静态ip Ubuntu10.10的网络配置 (总结的比较好些) 由于我的虚拟机中的Ubuntu 14.04中,只安装了一个gitlab,gitlab中配置了固定i ...
- eclipse 好用的插件安装地址集合【持续更新】
1.PropertiesEditor (编辑properties文件的插件): http://propedit.sourceforge.jp/eclipse/updates/ 2.Aptana Stu ...
- Xcode7 网络请求报错
xcode7 网络报错: The resource could not be loaded because the App Transport Security policy reguir 原因:iO ...
- (转)unity开发相关环境(vs、MonoDevelop)windows平台编码问题
转自: http://www.cnblogs.com/sevenyuan/archive/2012/12/06/2805114.html 1.unity会爆出错误: There are inconsi ...
- js中对闭包的理解
本人丝一枚,在刚刚过去的javascript学习中,对闭包这个知识真是,听课两分钟,懵逼一整天.今天闲来没事,看了下闭包.话不多说先上代码. <!DOCTYPE html> <htm ...
- Eclipse Memory Analysis进行堆转储文件分析
生成堆转储文件 新建项目,设置Eclispe Java堆的大小: (1)限制Java堆大小:将最小值 -Xms参数与最大值-Xmx参数设置一样可避免堆的扩展 -Xmx20m -Xms2 ...
- 暑假集训(3)第一弹 -----还是畅通工程(hdu1233)
题意梗概:N(n<100)个村子想要富起来,自然就要先修路,不过到底还是没富起来,所以陷入了一个怪圈 :资金不足->修不起路->资金不足...... 为了实现走向全民小康社会,全面实 ...
- sgu 102 Coprimes
太水了, 我都不忍心发题解, 但毕竟是sgu上一道题, 我试试能不能一直这么写下去,就是求phi,上代码 #include <cstdio> #include <cstring> ...
- php的运行环境介绍
php软件已下载在我的百度云:页面底部有地址,如有需要欢迎下载! 一:如何让php环境运行php代码? 直接使用php软件直接运行代码文件中的php代码 在B/S结构中让Apache使用php软件运行 ...