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. 内核知识第八讲,PDE,PTE,页目录表,页表的内存管理

    内核知识第八讲,PDE,PTE,页目录表,页表的内存管理 一丶查看GDT表. 我们通过WinDbg + 虚拟机可以进行双机调试.调试一下看下GDT表 我们知道,GDT表中.存储的是存储段信息. 保存了 ...

  2. dead loop、continue & break、while...else语句

    Dead loop 死循环,一经触发就会永远运行下去. continue & break 如果在循环过程中,因为某些原因,你不想继续循环了,就要用到break 或 continue语句. br ...

  3. DQN算法

    DQN算法:基础入门看看 # -*- coding: utf-8 -*- import random import gym import numpy as np from collections im ...

  4. 什么是CDN加速?(转载)

    随着互联网的发展,用户在使用网络时对网站的浏览速度和效果愈加重视,但由于网民数量激增,网络访问路径过长,从 而使用户的访问质量受到严重影响.特别是当用户与网站之间的链路被突发的大流量数据拥塞时,对于异 ...

  5. 爬虫、请求库selenium

    阅读目录 一 介绍 二 安装 三 基本使用 四 选择器 五 等待元素被加载 六 元素交互操作 七 其他 八 项目练习 一 介绍 selenium最初是一个自动化测试工具,而爬虫中使用它主要是为了解决r ...

  6. windows下apache配置虚拟主机

    因为有多个laravel项目需要配置根目录到public下面,所以要配置多个虚拟主机 方法一:添加端口号 第一步:进入apache的目录 Apache24\conf 找到 httpd.conf 文件, ...

  7. PEP8 Python 编码规范整理

    一 代码编排1 缩进.4个空格的缩进(编辑器都可以完成此功能),不使用Tap,更不能混合使用Tap和空格.2 每行最大长度79,换行可以使用反斜杠,最好使用圆括号.换行点要在操作符的后边敲回车.3 类 ...

  8. ubuntu下查看-卸载软件(卸载.net core sdk的方法)

    查看已安装的包:dpkg --list 查看正则匹配的包:dpkg --list 'dotnet-*' //查看以dotnet-开头的包 卸载匹配的包:sudo apt-get --purge rem ...

  9. Error : Invalid Allocation Size :·····Bytes 以及 abort() has been called

    把这两个Error放在一起,主要是因为在写代码的时候发现,他们有公共的错误. (一)Invalid Allocation Size 主要是因为new分配内存出了问题,从直观翻译来看,应该是内存分配长度 ...

  10. HDU 1024 Max Sum Plus Plus【动态规划求最大M子段和详解 】

    Max Sum Plus Plus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...