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. C# 获取当前,相对,绝对路径

    一.C#获取当前路径的方法: 1. System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName -获取模块的完整路径. 2. ...

  2. django makemigrations的一个特性

    Migrations will run the same way on the same dataset and produce consistent results, meaning that wh ...

  3. python运维开发之路02

    年底事多,在公司忙成狗,难得把博客更新了下 本章主要内容是collections模块的介绍(队列,计数器,默认字典,有序字典,可命名元组,以及简单介绍深浅拷贝!) collections模块 coll ...

  4. centos忘记root密码,重新设置的方法

    今天重新装了一个centos6.6,好像root密码没有叫我设置吧,然后用虚拟机开始安装之前的密码登录显示失败,所以有了下面的彩蛋.....Helloween... 在虚拟机安装了Centos,今天要 ...

  5. java编程思想-java 异常使用指南

    应该在以下情况下使用异常: 在恰当的级别处理问题(在知道该如何处理的情况下才捕获异常). 解决问题并且重新调用产生异常的方法. 进行少许修补,然后绕过异常发生的地方继续执行. 用别的数据进行计算,以代 ...

  6. 【原】redux异步操作学习笔记

    摘要: 发觉在学习react的生态链中,react+react-router+webpack+es6+fetch等等这些都基本搞懂的差不多了,可以应用到实战当中,唯独这个redux还不能,学习redu ...

  7. log4net详解(转载)

    1.概述 log4net是.Net下一个非常优秀的开源日志记录组件.log4net记录日志的功能非常强大.它可以将日志分不同的等级,以不同的格式,输出到不同的媒介.本文主要是介绍如何在Visual S ...

  8. WinForm------GridControl的部分属性介绍

    参考其它链接: http://www.cnblogs.com/djian/archive/2010/11/19/1881579.html //注意:在定义GridControl里面的FileName里 ...

  9. Oracle - 数据库的实例、表空间、用户、表之间关系

    完整的Oracle数据库通常由两部分组成:Oracle数据库和数据库实例. 1) 数据库是一系列物理文件的集合(数据文件,控制文件,联机日志,参数文件等): 2) Oracle数据库实例则是一组Ora ...

  10. Sky Box

    http://www.keithlantz.net/2011/10/rendering-a-skybox-using-a-cube-map-with-opengl-and-glsl/ http://o ...