Print Article

                    Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)
                           Total Submission(s): 7960    Accepted Submission(s): 2465

Problem Description
Zero
has an old printer that doesn't work well sometimes. As it is antique,
he still like to use it to print articles. But it is too old to work for
a long time and it will certainly wear and tear, so Zero use a cost to
evaluate this degree.
One day Zero want to print an article which has
N words, and each word i has a cost Ci to be printed. Also, Zero know
that print k words in one line will cost

M is a const number.
Now Zero want to know the minimum cost in order to arrange the article perfectly.
 
Input
There are many test cases. For each test case, There are two numbers N and M in the first line (0 ≤ n ≤ 500000, 0 ≤ M ≤ 1000). Then, there are N numbers in the next 2 to N + 1 lines. Input are terminated by EOF.
 
Output
A single number, meaning the mininum cost to print the article.
 
Sample Input
5 5
5
9
5
7
5
 
Sample Output
230
 
Author
Xnozero
 
Source
 

【思路】

斜率优化。

设f[i],则转移式为f[i]=min{f[j]+(C[i]-C[j])^2+M},1<=j<i

进一步得:f[i]=min{ (f[j]+C[j]^2-2*C[i]*C[j])+(C[i]^2+M) }

       设y(j)=f[j]+C[j]^2,a[i]=-*C[i],x(j)=C(j),则f[i]=min{y(j)+2*a[i]*x(j)}+C[i]^2+M

则要求min p=y+2ax , 单调队列维护下凸包。

【代码】

 #include<cstdio>
#include<cstring>
#include<iostream>
using namespace std; const int N = +; struct point { int x,y;
}q[N],now;
int L,R,n,m,C[N],f[N];
int cross(point a,point b,point c) {
return (b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x);
}
void read(int& x) {
char c=getchar(); while(!isdigit(c)) c=getchar();
x=; while(isdigit(c)) x=x*+c-'' , c=getchar();
}
int main() {
while(scanf("%d%d",&n,&m)==) {
for(int i=;i<=n;i++)
read(C[i]) , C[i]+=C[i-];
L=R=;
for(int i=;i<=n;i++) {
while(L<R && q[L].y-*C[i]*q[L].x>=q[L+].y-*C[i]*q[L+].x) L++;
now.x=C[i]; //计算xi
now.y=q[L].y-*C[i]*q[L].x+*C[i]*C[i]+m; //计算yi=f[i]+b[i]^2 = min p+a[i]^2+b[i]^2+M
while(L<R && cross(q[R-],q[R],now)<=) R--;
q[++R]=now;
}
printf("%d\n",q[R].y-C[n]*C[n]);
}
return ;
}

HDU 3507 Print Article(DP+斜率优化)的更多相关文章

  1. HDU 3507 [Print Article]DP斜率优化

    题目大意 给定一个长度为\(n(n \leqslant 500000)\)的数列,将其分割为连续的若干份,使得 $ \sum ((\sum_{i=j}^kC_i) +M) $ 最小.其中\(C_i\) ...

  2. HDU 3507 Print Article(斜率优化DP)

    题目链接 题意 : 一篇文章有n个单词,如果每行打印k个单词,那这行的花费是,问你怎么安排能够得到最小花费,输出最小花费. 思路 : 一开始想的简单了以为是背包,后来才知道是斜率优化DP,然后看了网上 ...

  3. HDU 3507 Print Article(斜率优化)

    显然的斜率优化模型 但是单调队列维护斜率单调性的时候出现了莫名的锅orz 代码 #include <cstdio> #include <algorithm> #include ...

  4. HDU 3507 Print Article(斜率优化推导)

    $dp$,斜率优化. 第一次做斜率优化的题目,看了一些题解,自己总结一下. 这题是说有$n$个数字,可以切成任意段,每一段的费用是这一段数字的和平方加上$M$.问最小费用是多少. 设$dp[i]$为$ ...

  5. hdu 3507 Print Article(斜率优化DP)

    题目链接:hdu 3507 Print Article 题意: 每个字有一个值,现在让你分成k段打印,每段打印需要消耗的值用那个公式计算,现在让你求最小值 题解: 设dp[i]表示前i个字符需要消耗的 ...

  6. DP(斜率优化):HDU 3507 Print Article

    Print Article Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)To ...

  7. HDU 3507 - Print Article - [斜率DP]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3507 Zero has an old printer that doesn't work well s ...

  8. HDU 3507 Print Article 斜率优化

    Print Article Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)To ...

  9. 斜率优化板题 HDU 3507 Print Article

    题目大意:输出N个数字a[N],输出的时候可以连续的输出,每连续输出一串,它的费用是 "这串数字和的平方加上一个常数M".n<=500000 我们设dp[i]表示输出到i的时 ...

随机推荐

  1. C#调用ActiveX控件

    背景:最近项目中需要用到ActiveX控件,项目是在.Net平台下开发的.因此就直接在项目中添加了对ActiveX控件的引用,添加引用成功.在代码中实例化类的实例也没有问题,但在调用其方法或属性时总是 ...

  2. jQuery 如何设置input checkbox 更有效 prop()

    问题:经常使用jQuery插件的attr方法获取checked属性值,获取的值的大小为未定义,此时可以用prop方法获取其真实值,下面介绍这两种方法的区别: 1.通过prop方法获取checked属性 ...

  3. 由C到C++的学习 ----Essential C++

    一.array[] 与 vector<int> vector1 1 array[] <- 此中要填写数组的大小,而且array[]自己是不知道自己的大小的 2.1 vector< ...

  4. Sdut 2151 Phone Numbers (山东省ACM第一届省赛题 A)

    题目描述 We know thatif a phone number A is another phone number B's prefix, B is not able to becalled. ...

  5. php微信2 获取自定义菜单中的access_token

    //自定义菜单中获取access_token    static function get_access_token($appid,$secret){        $url="https: ...

  6. 去掉Visual Studio 编辑器里中文注释的红色波浪线 转载

    我们通常用visual studio进行开发的时候,我们通常会用到一款比较流行比较方便的插件,那就是Visual Assist X,它可以增强Microsoft开发环境下的编辑能力,支持C/C++,C ...

  7. html本地存储尝试

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  8. Javascript线程及定时机制

    setTimeout.setInterval的使用 Javascript api文档中定义setTimeout和setInterval第二个参数意义分别为间隔多少毫秒后回调函数被执行和每隔多少毫秒回调 ...

  9. Balsamiq Mockups

    Balsamiq Mockups完全手册 2010.03.18 发布 48,066 浏览 什么是Balsamiq Mockups Balsamiq Mockups出自加利福尼亚州的Balsamiq工作 ...

  10. C#中标准Dispose模式的实现

    http://www.cnblogs.com/luminji/archive/2011/03/29/1997812.html 需要明确一下C#程序(或者说.NET)中的资源.简单的说来,C#中的每一个 ...