Print Article

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

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   |   We have carefully selected several similar problems for you:  3506 3501 3504 3505 3498 
 
Code:
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#define INF 100000000000000008
using namespace std;
long long f[],sum[];
int n,m; int main(){
while(scanf("%d%d",&n,&m)==){
for(int i=;i<=n;i++)
f[i]=INF;
for(int i=;i<=n;i++){
int x;
scanf("%d",&x);
sum[i]=sum[i-]+x;
}
int flag=,k=;
for(int i=;i<=n;i++){
for(int j=flag;j<=i;j++)
if(f[i]>f[j]+(sum[i]-sum[j])*(sum[i]-sum[j])+m){
k=j;
f[i]=f[j]+(sum[i]-sum[j])*(sum[i]-sum[j])+m;
}
flag=k;
}
printf("%lld\n",f[n]);
}
}

hdu3507 Print Article的更多相关文章

  1. HDU3507 Print Article —— 斜率优化DP

    题目链接:https://vjudge.net/problem/HDU-3507 Print Article Time Limit: 9000/3000 MS (Java/Others)    Mem ...

  2. hdu3507 Print Article[斜率优化dp入门题]

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

  3. hdu3507 Print Article(斜率DP优化)

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

  4. hdu3507 Print Article(斜率优化入门)(pascal)

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

  5. HDU3507 Print Article(斜率优化dp)

    前几天做多校,知道了这世界上存在dp的优化这样的说法,了解了四边形优化dp,所以今天顺带做一道典型的斜率优化,在百度打斜率优化dp,首先弹出来的就是下面这个网址:http://www.cnblogs. ...

  6. HDU3507 Print Article (斜率优化DP基础复习)

    pid=3507">传送门 大意:打印一篇文章,连续打印一堆字的花费是这一堆的和的平方加上一个常数M. 首先我们写出状态转移方程 :f[i]=f[j]+(sum[i]−sum[j])2 ...

  7. HDU-3507 Print Article (斜率优化)

    题目大意:将n个数分成若干个区间,每个区间的代价为区间和的平方加上一个常数m,求最小代价. 题目分析:定义状态dp(i)表示前 i 个数已经分好的最小代价,则状态转移方程为 dp(i)=min(dp( ...

  8. 2018.08.29 hdu3507 Print Article(斜率优化dp)

    传送门 这应该算是斜率优化的模板题了. 就是要求打印n个数,每个数有一个参数a[i],每打印一段连续的数[l,r]需要的花费是(a[[l]+...+a[r])2+m" role=" ...

  9. HDU3507 print article【斜率优化dp】

    打印文章 时间限制:9000/3000 MS(Java / Others)内存限制:131072/65536 K(Java / Others) 总共提交:14521已接受提交:4531 问题描述 零有 ...

随机推荐

  1. HTML基础知识(表格、表单)

    6.表格 l  概念:表格一定具有行和列 注:使用<thead><tbody><tfoot>,使浏览器能独立于表格表头和表格页脚的表格主体滚动.当包含多个页面的表格 ...

  2. 加载进度圈,带遮罩层(jquery)

    如图: Js下载地址:http://files.cnblogs.com/files/holdon521/cvi_busy_lib.js 如下使用实例: <script src="/st ...

  3. spring使用之旅(一) ---- bean的装配

           基础配置 启用组件扫描配置                     Java类配置文件方式 package com.springapp.mvc.application;   import ...

  4. springboot之集成mybatis mongo shiro druid redis jsp

    闲来无事,研究一下spingboot  发现好多地方都不一样了,第一个就是官方默认不支持jsp  于是开始狂找资料  终于让我找到了 首先引入依赖如下: <!-- tomcat的支持.--> ...

  5. Mac 安装 Gradle

    首先下载 Gradle 通过官网进行下载 https://gradle.org 下载的文件名可能是 gradle-3.3-bin.zip 解压 将此文件解压到任意位置,如解压到 /usr/local ...

  6. BZOJ 2257: [Jsoi2009]瓶子和燃料【数论:裴蜀定理】

    2257: [Jsoi2009]瓶子和燃料 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1326  Solved: 815[Submit][Stat ...

  7. redis3.0 集群在windows上的配置(转)

    1. 安装Redis版本:win-3.0.501https://github.com/MSOpenTech/redis/releases页面有,我下载的是zip版本的:Redis-x64-3.0.50 ...

  8. 【转载】keil5中加入STM32F10X_HD,USE_STDPERIPH_DRIVER的原因

    初学STM32,在RealView MDK 环境中使用STM32固件库建立工程时,初学者可能会遇到编译不通过的问题.出现如下警告或错误提示: warning: #223-D: function &qu ...

  9. Mysql开启远程连接方法

    分类: 数据库开发技术 解决MySQL不允许从远程访问的方法 开启 MySQL 的远程登陆帐号有两大步: 1.确定服务器上的防火墙没有阻止 3306 端口. MySQL 默认的端口是 3306 ,需要 ...

  10. ExtJS是一种主要用于创建前端用户界面,是一个基本与后台技术无关的前端ajax框架。

    ExtJS是一种主要用于创建前端用户界面,是一个基本与后台技术无关的前端ajax框架.