http://www.lydsy.com/JudgeOnline/problem.php?id=1010

蛋疼用latex写了份题解。。

2015.03.07 upd:很多东西可能有问题,最好看下边提供的链接的题解

参考:http://www.cnblogs.com/proverbs/archive/2012/10/06/2713109.html

#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
#define pii pair<int, int>
#define mkpii make_pair<int, int>
#define pdi pair<double, int>
#define mkpdi make_pair<double, int>
#define pli pair<ll, int>
#define mkpli make_pair<ll, int>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%d", a)
#define dbg(x) cout << (#x) << " = " << (x) << endl
#define error(x) (!(x)?puts("error"):0)
#define printarr2(a, b, c) for1(_, 1, b) { for1(__, 1, c) cout << a[_][__]; cout << endl; }
#define printarr1(a, b) for1(_, 1, b) cout << a[_] << '\t'; cout << endl
inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
inline const ll max(const ll &a, const ll &b) { return a>b?a:b; }
inline const ll min(const ll &a, const ll &b) { return a<b?a:b; } const int N=50005;
int n, l, front, tail, q[N];
ll s[N], d[N], f[N], c;
inline ll sqr(ll a) { return a*a; }
inline double x(int j, int k) { return (double)(d[k]-d[j]+sqr(f[k]+c)-sqr(f[j]+c))/2.0/(double)(f[k]-f[j]); }
int main() {
read(n); read(l);
for1(i, 1, n) s[i]=s[i-1]+(ll)getint();
for1(i, 1, n) f[i]=s[i]+i;
c=l+1;
tail=1;
for1(i, 1, n) {
while(front+1<tail && x(q[front], q[front+1])<=f[i]) ++front;
int j=q[front];
d[i]=d[j]+sqr(f[i]-f[j]-c);
while(front+1<tail && x(q[tail-2], q[tail-1])>=x(q[tail-1], i)) --tail;
q[tail++]=i;
}
printf("%lld\n", d[n]);
return 0;
}

  


Description

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
4

Sample Output

1

HINT

 

Source

 

【BZOJ】1010: [HNOI2008]玩具装箱toy(dp+斜率优化)的更多相关文章

  1. BZOJ 1010: [HNOI2008]玩具装箱toy [DP 斜率优化]

    1010: [HNOI2008]玩具装箱toy Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 9812  Solved: 3978[Submit][St ...

  2. BZOJ.1010.[HNOI2008]玩具装箱toy(DP 斜率优化/单调队列 决策单调性)

    题目链接 斜率优化 不说了 网上很多 这的比较详细->Click Here or Here //1700kb 60ms #include<cstdio> #include<cc ...

  3. BZOJ 1010: [HNOI2008]玩具装箱toy(斜率优化dp)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1010 题意: 思路: 容易得到朴素的递归方程:$dp(i)=min(dp(i),dp(k)+(i-k ...

  4. BZOJ 1010 [HNOI2008]玩具装箱toy:斜率优化dp

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1010 题意: 有n条线段,长度分别为C[i]. 你需要将所有的线段分成若干组,每组中线段的 ...

  5. 1010: [HNOI2008]玩具装箱toy [dp][斜率优化]

    Description P教授要去看奥运,但是他舍不下他的玩具,于是他决定把所有的玩具运到北京.他使用自己的压缩器进行压缩,其可以将任意物品变成一堆,再放到一种特殊的一维容器中.P教授有编号为1... ...

  6. 1010: [HNOI2008]玩具装箱toy(斜率优化)

    1010: [HNOI2008]玩具装箱toy Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 12280  Solved: 5277[Submit][S ...

  7. [HNOI2008]玩具装箱TOY --- DP + 斜率优化 / 决策单调性

    [HNOI2008]玩具装箱TOY 题目描述: P教授要去看奥运,但是他舍不下他的玩具,于是他决定把所有的玩具运到北京. 他使用自己的压缩器进行压缩,其可以将任意物品变成一堆,再放到一种特殊的一维容器 ...

  8. BZOJ1010: [HNOI2008]玩具装箱toy(dp+斜率优化)

    Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 12451  Solved: 5407[Submit][Status][Discuss] Descript ...

  9. BZOJ 1010: [HNOI2008]玩具装箱toy | 单调队列优化DP

    原题: http://www.lydsy.com/JudgeOnline/problem.php?id=1010 题解: #include<cstdio> #include<algo ...

  10. BZOJ 1010: [HNOI2008]玩具装箱toy 斜率优化DP

    1010: [HNOI2008]玩具装箱toy Description P教授要去看奥运,但是他舍不下他的玩具,于是他决定把所有的玩具运到北京.他使用自己的压缩器进行压缩,其可以将任意物品变成一堆,再 ...

随机推荐

  1. Sublime key

    -– BEGIN LICENSE -– TwitterInc 200 User License EA7E-890007 1D77F72E 390CDD93 4DCBA022 FAF60790 61AA ...

  2. laravel 安装环境安了三天!!

    各种报错,各种升级,各种重装,重启!! 记录一下一些错误吧,,, 错误太复杂,,,, 原因:版本问题!.CPU虚拟化问题.win10问题.软件兼容性问题.还有就是各种不细心啥的         分割线 ...

  3. 转:VB用ADO连接SQLServer数据库

    '数据源信息常量 Public Const conn As String = "Provider = SQLOLEDB.1;Password = sa; UserID = sa; Initi ...

  4. 学习使用Jmeter做压力測试(一)--压力測试基本概念

    一.性能測试的概念         性能測试是通过自己主动化的測试工具模拟多种正常峰值及异常负载条件来对系统的各项性能指标进行測试.负载測试和压力測试都属于性能測试,两者能够结合进行. 通过负载測试, ...

  5. Adobe Acrobat Pro 修改背景色

      Adobe Acrobat Pro 如何修改背景色 CreateTime--2017年8月1日10:05:58Author:Marydon 参考:百度经验 在菜单栏选择“编辑”,下拉栏中选择最后一 ...

  6. JDBC 事务(二)回滚到保存点

    public class SavePointTest { /**      * @param args      * @throws SQLException      */     public s ...

  7. windows下安装redis及其客户端

    首先下载redis安装包:https://github.com/MSOpenTech/redis/releases 解压安装包到相应文件夹,任何盘符都行. 文件介绍:redis-server.exe: ...

  8. sphinx和mysql like对比

    一共有3093326条企业数据,其中sphinx代码如下: <?php function microtime_float() { list($usec, $sec) = explode(&quo ...

  9. HDU 4927 Series 1 ( 组合+高精度)

    pid=4927">Series 1 大意: 题意不好翻译,英文看懂也不是非常麻烦,就不翻译了. Problem Description Let A be an integral se ...

  10. 【剑指Offer面试题】 九度OJ1510:替换空格

    c/c++ 中的字符串以"\0"作为结尾符.这样每一个字符串都有一个额外字符的开销. 以下代码将造成内存越界. char str[10]; strcpy(str, "01 ...