【BZOJ 1010】 [HNOI2008]玩具装箱toy (斜率优化)
1010: [HNOI2008]玩具装箱toy
Time Limit: 1 Sec Memory Limit: 162 MB
Submit: 9330 Solved: 3739Description
P教授要去看奥运,但是他舍不下他的玩具,于是他决定把所有的玩具运到北京。他使用自己的压缩器进行压
缩,其可以将任意物品变成一堆,再放到一种特殊的一维容器中。P教授有编号为1...N的N件玩具,第i件玩具经过
压缩后变成一维长度为Ci.为了方便整理,P教授要求在一个一维容器中的玩具编号是连续的。同时如果一个一维容
器中有多个玩具,那么两件玩具之间要加入一个单位长度的填充物,形式地说如果将第i件玩具到第j个玩具放到一
个容器中,那么容器的长度将为 x=j-i+Sigma(Ck) i<=K<=j 制作容器的费用与容器的长度有关,根据教授研究,
如果容器长度为x,其制作费用为(X-L)^2.其中L是一个常量。P教授不关心容器的数目,他可以制作出任意长度的容
器,甚至超过L。但他希望费用最小.Input
第一行输入两个整数N,L.接下来N行输入Ci.1<=N<=50000,1<=L,Ci<=10^7
Output
输出最小费用
Sample Input
5 4
3
4
2
1
4Sample Output
1
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
using namespace std;
#define Maxn 50010
#define LL long long LL c[Maxn],d[Maxn],f[Maxn];
struct node
{
LL x,y;
}t[Maxn];int len; LL n,l; void init()
{
scanf("%lld%lld",&n,&l);
for(int i=;i<=n;i++)
{
scanf("%lld",&c[i]);
d[i]=d[i-]+c[i]+;
}
f[]=;d[]=;
// f[1]=(c[1]-l)*(c[1]-l);
l++;
} bool check(int x,int y,LL k)
{
return (t[y].y-t[x].y)<=k*(t[y].x-t[x].x);
} bool check2(int x,int y,int z)
{
return (t[z].y-t[y].y)*(t[y].x-t[x].x)<=(t[y].y-t[x].y)*(t[z].x-t[y].x);
} void ffind()
{
len=;int st=;
t[++len].x=,t[len].y=;
for(int i=;i<=n;i++)
{
while(st<len&&check(st,st+,*d[i])) st++;
f[i]=-*d[i]*t[st].x+t[st].y+d[i]*d[i]-*d[i]*l+l*l;
t[].x=d[i];t[].y=f[i]+d[i]*d[i]+*d[i]*l;
while(st<len&&check2(len-,len,))
len--;
t[++len]=t[];
}
// for(int i=1;i<=n;i++) printf("%lld\n",f[i]);
printf("%lld\n",f[n]);
} int main()
{
init();
ffind();
return ;
}
[BZOJ 1010]
2016-09-16 16:53:22
【BZOJ 1010】 [HNOI2008]玩具装箱toy (斜率优化)的更多相关文章
- BZOJ 1010: [HNOI2008]玩具装箱toy 斜率优化DP
1010: [HNOI2008]玩具装箱toy Description P教授要去看奥运,但是他舍不下他的玩具,于是他决定把所有的玩具运到北京.他使用自己的压缩器进行压缩,其可以将任意物品变成一堆,再 ...
- Bzoj 1010: [HNOI2008]玩具装箱toy(斜率优化)
1010: [HNOI2008]玩具装箱toy Time Limit: 1 Sec Memory Limit: 162 MB Description P教授要去看奥运,但是他舍不下他的玩具,于是他决定 ...
- 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 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 ...
- bzoj1010[HNOI2008]玩具装箱toy 斜率优化dp
1010: [HNOI2008]玩具装箱toy Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 11893 Solved: 5061[Submit][S ...
- 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 题意: 有n条线段,长度分别为C[i]. 你需要将所有的线段分成若干组,每组中线段的 ...
- BZOJ.1010.[HNOI2008]玩具装箱toy(DP 斜率优化/单调队列 决策单调性)
题目链接 斜率优化 不说了 网上很多 这的比较详细->Click Here or Here //1700kb 60ms #include<cstdio> #include<cc ...
- 【bzoj1010】[HNOI2008]玩具装箱toy 斜率优化dp
题目描述 P教授要去看奥运,但是他舍不下他的玩具,于是他决定把所有的玩具运到北京.他使用自己的压缩器进行压缩,其可以将任意物品变成一堆,再放到一种特殊的一维容器中.P教授有编号为1...N的N件玩具, ...
随机推荐
- 转:XMLP报表导出为excel时设置文本不自动转为数字
转自:http://yedward.net/?id=337 对于这个问题,只要在RTF模版中设置下强制LTR即可,设置方法如下: 图1:勾选强制LTR 也可以自己输入下面的代码: <fo:bid ...
- Java 内存分析图
client -------------------------- public class Client{ public static void main(String[] args){ Perso ...
- C#创建自定义配置节点
转载:http://www.educity.cn/develop/495003.html 在.Net应用程序中我们经常看到VS为我们生成的项目工程中都会含有app.config或者web.connfi ...
- problems record
1,java类中字体MS Gothic 2,得到请求资源,例如,http://localhost:8080 public static URL serverURL(HttpServletRequest ...
- com.sun.org.apache.commons.logging.LogConfigurationException: java.lang.NullPointerException
在日志中, 查看导入的包是否是 import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory;
- Linux apt-get error
csh@csh-laptop:~/ejabberd-15.03$ sudo apt-get install mysqlReading package lists... DoneBuilding dep ...
- 九度OJ 1107 搬水果 -- 哈夫曼树 2011年吉林大学计算机研究生机试真题
题目地址:http://ac.jobdu.com/problem.php?pid=1107 题目描述: 在一个果园里,小明已经将所有的水果打了下来,并按水果的不同种类分成了若干堆,小明决定把所有的水果 ...
- 模板:优先队列(priority_queue)
#include <iostream> #include <cstdio> #include <queue> #include <vector> usi ...
- 虚拟机中如何Linux系统如何访问PC硬盘中的文件(如何将windows下的文件夹挂载到linux虚拟机下)
这段时间决定学习嵌入式,变打算安装个Linux系统先熟悉一下Linux系统的使用,但自己电脑上安装的win7系统又不想装双系统,一是闲麻烦,二是由于对Linux系统不熟悉担心会因为自己的误操作而损坏系 ...
- greenlet代码解读
协程 上次已经讲解了协程的的实现方法,和我对协程的一些理解.这里指我就先以代码说明协程的运行.def test1(): print 12 (2) gr2.switch() ...