Print Article

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

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
 



Recommend
zhengfeng
 
 #include <iostream>
#include <cstdio>
#include <cstring> using namespace std; typedef long long int LL; LL dp[],sum[],deq[];
int n,m,s,t,e; double slope(int i,int j)
{
return (double)(dp[i]+sum[i]*sum[i]-dp[j]-sum[j]*sum[j])/(sum[i]-sum[j]);
} int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
sum[]=;
for(int i=;i<=n;i++)
{
scanf("%d",sum+i);
sum[i]+=sum[i-];
}
s=;
for(int i=;i<=n;i++)
{
if(sum[i]!=sum[s])
{
s++;
sum[s]=sum[i];
}
}
n=s;
s=,e=,dp[]=,deq[]=;
for(int i=;i<=n;i++)
{
while(s<e&&slope(deq[s],deq[s+])<=*sum[i]) s++;
int j=deq[s];
dp[i]=dp[j]+(sum[i]-sum[j])*(sum[i]-sum[j])+m;
while(s<e&&slope(deq[e-],deq[e])>=slope(i,deq[e])) e--; e++;
deq[e]=i;
}
printf("%d\n",dp[n]);
}
return ;
}

HDOJ 3507 Print Article的更多相关文章

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

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

  2. HDU 3507 Print Article 斜率优化

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

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

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

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

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

  5. 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 ...

  6. [HDU 3507]Print Article

    Description Zero has an old printer that doesn't work well sometimes. As it is antique, he still lik ...

  7. HDU 3507 Print Article(CDQ分治+分治DP)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=3507 [题目大意] 将长度为n的数列分段,最小化每段和的平方和. [题解] 根据题目很容易得到dp ...

  8. ●HDU 3507 Print Article

    题链: http://acm.hdu.edu.cn/showproblem.php?pid=3507 题解: 斜率优化DP 一个入门题,就不给题解了,网上的好讲解很多的.   这里就只提一个小问题吧( ...

  9. hdu 3507 Print Article —— 斜率优化DP

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=3507 设 f[i],则 f[i] = f[j] + (s[i]-s[j])*(s[i]-s[j]) + m ...

随机推荐

  1. HDU 1166 敌兵布阵(线段树模板题)

    题目链接: 传送门 敌兵布阵 Time Limit: 2000MS     Memory Limit: 32768 K Description C国的死对头A国这段时间正在进行军事演习,所以C国间谍头 ...

  2. Mac xcode 编译产生app的路径

    .../<current User>/Library/Developer/XCode/DerivedData/<Project name>-<other characte ...

  3. CSS3动画(性能篇)

    写在前面 高性能移动Web相较PC的场景需要考虑的因素也相对更多更复杂,我们总结为以下几点: 流量.功耗与流畅度. 在PC时代我们更多的是考虑体验上的流畅度,而在Mobile端本身丰富的场景下,需要额 ...

  4. json转换成对象

    在json转换成对象时,json的key会与java 类的字段一一对应.如果没有映射上的java字段会在该数据类型上填充默认值,如int 0,String null 等. 没有映射的json key在 ...

  5. 【转】Airbnb React编码规范

    Airbnb的编码规范是在业界非常流行的一套规范,而且它一直都在进化,推出最新技术的规范 原文:https://zhuanlan.zhihu.com/p/20616464 用更合理的方式书写React ...

  6. 未签名有元程序集 Unsigned Friend Assemblies

    C#中的访问修饰符internal可以使类型在同程序集中可以被相互访问.但有时会有这样一个要求,我们希望一个程序集中的类型可以被外部的某些程序集访问,如果设置成public的话,就被所有的外部程序集访 ...

  7. Git删除tag

    git tag -d v2016062101 删除本地tag git push origin --delete tag v2016062101 删除远程tag

  8. Linq------各种查询语句大全

    查询Title列的第一个值 string str = db.Webs.Select(p => p.Title).FirstOrDefault(); 根据ID,查询Title列的第一个值 b.We ...

  9. 9月20日上午JavaScript函数

    函数 一.  函数定义 函数又叫方法,在程序里面函数是用来执行某些特定功能的代码.为了减少重复使用代码,可以把特定功能的代码做成函数,需要使用时拿出来调用.alert();就是一个很常见的.简单的函数 ...

  10. .net4.0及Silverlight_Tools for vs2008sp1安装失败解决办法

    安装.net framework 4.0失败,出现HRESULT 0xc8000222错误代码 1.开始-运行-输入cmd,运行命令     net stop WuAuServ 2.开始-运行-输入  ...