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. iOS “智慧气象”APP中用到的第三方框架汇总

    “智慧气象”是我最近在公司接手的项目,已经完成最新版本的更新并上架,在此分享下其中用到的第三方框架的使用. 应用地址:APP商店搜索“智慧气象” MJRefresh(下拉刷新)业界知名下拉刷新框架就不 ...

  2. PowerDesigner 学习笔记

    软件:PowerDesginer16.5 首先说一下对应的模型 New Model  --->  Model Type 作为一个英语渣,实在是压力颇大,然而汉化经常会导致无故的BUG,所以简单翻 ...

  3. AngularJs $location 和 $window

    $location $location服务解析浏览器地址中的url(基于window.location)并且使url在应用程序中可用.将地址栏中的网址的变化反映到$location服务和$locati ...

  4. PHP ServerPush (推送) 技术的探讨

    2016年11月29日17:51:03 转自:http://www.cnblogs.com/hnrainll/archive/2013/05/07/3064874.html 需求: 我想做个会员站内通 ...

  5. python编码

    一.编码 常见的编码比较: ascii:1个字节 unicode:2个字节 utf-8:英文1个字节,汉字3个字节 二.一个编码问题 问:如下代码设置了在代码中添加了coding: utf-8,但是在 ...

  6. IOS基础之 (设计模式)

    一 工厂方法 工厂方法方便我们快速创建类的实例的方法.通过工厂方法,可以让调用过程更加清晰. Person.h #import <Foundation/Foundation.h> @int ...

  7. EmgnCv进行轮廓寻找和计算物体凸包

    http://blog.csdn.net/qq_22033759/article/details/48029493 一.轮廓寻找 用的是FindContours函数,在CvInvoke中 不过需要用到 ...

  8. 使用Keil uVision下载hex文件

    在uVision3/uVision4/uVision5中,可以创建一个项目用来下载HEX文件到flash里面. 具体步骤如下: 1.  在菜单中,选择 Project - New Project... ...

  9. css010 css的transform transition和animation

    css010 css的transform transition和animation 看着没有一个能想起他们是干什么的.. 1.         Transform    Transform(变形) r ...

  10. javascript之简单的选择排序法

    基本思想: 比对数组中元素,相等者输出元素在数组的下标,否则就输出没找到! 代码如下: function Orderseach(array,findVal){ var temp = false; // ...