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. python统计nginx脚本信息

    #!/usr/bin/env python # -*- coding: utf-8 -*- import urllib2 import json import subprocess import th ...

  2. 你所知道好玩有趣的 iOS URL schemes 有哪些?

    QQ的url是 mqq:// 微信是weixin:// 淘宝taobao:// 点评dianping:// dianping://search 微博 sinaweibo:// 名片全能王camcard ...

  3. 为你解惑之WPF经典9问详解

    本文解答了关于WPF的9个最常见的问题.从某种意义上讲,这两种技术是相互关联的:它们都是关于界面表现的技术,更进一步的,Silverlight是基于WPF的,是它的一个子集.不仅从理论上介绍了这两种技 ...

  4. CSS--值和单位

    等价颜色表 什么叫Web安全色 所谓的“web安全”颜色是指在256色计算机系统上总能避免抖动的颜色. Web安全颜色可以表示为RGB值为20%和51(相应的十六进制值为33)的倍数. 如果使用RGB ...

  5. iOS - CALayer相关(CATransform3D)

    一.图层的几何 图层的几何简单通俗,图层的所有几何属性(包括矩阵变换),都可以有隐式和显式动画. 图层几何的属性: 1.position是CGPoint值,她指定图层相对于她图层的位置,该值基于父图层 ...

  6. linux系统性能监视命令

    preface as a linux engineer,you should know how to use these command of monitor system,so let's lear ...

  7. HTML meta viewport属性详细说明

    viewport并非只是ios上的独有属性,在android.winphone上同样也有viewport,下面为大家详细介绍下HTML meta viewport 什么是Viewport 手机浏览器是 ...

  8. centos 查看cpu个数、核数

    # 总核数 = 物理CPU个数 X 每颗物理CPU的核数 # 总逻辑CPU数 = 物理CPU个数 X 每颗物理CPU的核数 X 超线程数 # 查看物理CPU个数 cat /proc/cpuinfo| ...

  9. Hadoop FS shell commands

    命令格式:hadoop fs -command -option args appendToFileUsage: hadoop fs -appendToFile <localsrc> ... ...

  10. You Can Do Research Too

    You Can Do Research Too I was recently discussing gatekeeping and the process of getting started in ...