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. A题笔记(4)

    No. 1384 这题没啥 不过网考成绩出了,发现我的口语分数相较其他人还挺高的~~~哈哈哈 Code::Blocks 有时在程序运行结束后,.exe 并没有结束,因而之后无论怎么调试和修改代码,运行 ...

  2. SQL Server 索引和视图【转】

    Ø 索引 1. 什么是索引 索引就是数据表中数据和相应的存储位置的列表,利用索引可以提高在表或视图中的查找数据的速度. 2. 索引分类 数据库中索引主要分为两类:聚集索引和非聚集索引.SQL Serv ...

  3. UIScrollView -2(UIScrollView 与 UIPageControl的使用): 分页查看图片

    1.初始化UIScrollView 2.设置初始化出来的UIScrollView的contentSize: myscrollview.contentSize =CGSizeMake(CGRectGet ...

  4. Windows phone 之Socket

    服务器端: using System; using System.Collections.Generic; using System.Linq; using System.Text; using Sy ...

  5. 【实习记】2014-08-26都是回车惹的祸——shell脚本必须是unix行尾

        事情由起:svn的url在excel里,我复制到txt文本下,vi做些文本处理,只提取了url,保存为url.txt.再用vi处理url.txt,加上svn checkout等词,变成可以运行 ...

  6. 【原创】CMD常用命令:解决实际问题

    1.查找某一目录下后缀名文某某的所有文件. 命令格式:dir *.mp3 /a -d/b/s >C:\Users\leemo\Desktop\total.txt MP3为文件后缀名.>是命 ...

  7. [转] 小tips: 使用&#x3000;等空格实现最小成本中文对齐 ---张鑫旭

    by zhangxinxu from http://www.zhangxinxu.com本文地址:http://www.zhangxinxu.com/wordpress/?p=4562 一.重见天日第 ...

  8. 关于js效果不提示就执行了刷新(解决 在h-ui框架中)

    parent.layer.msg('保存成功!<script>setTimeout("window.location.reload();",1100);<\/sc ...

  9. [Linux]Ubuntu下如何将普通用户提升到root权限

    转至:http://jingyan.baidu.com/album/6181c3e0780131152ef153ff.html?picindex=0&qq-pf-to=pcqq.c2c  在u ...

  10. ubuntu下mysql安装与测试

    原文地址: http://www.cnblogs.com/zhuyp1015/p/3561470.html 注意:原文地址中,最后g++ 编译源代码时少了个字母.添上即可. ubuntu上安装mysq ...