博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu3507 Print Article
阅读量:4677 次
发布时间:2019-06-09

本文共 1793 字,大约阅读时间需要 5 分钟。

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:            
 
Code:
#include
#include
#include
#include
#define INF 100000000000000008using namespace std;long long f[500008],sum[500008];int n,m;int main(){ while(scanf("%d%d",&n,&m)==2){ for(int i=1;i<=n;i++) f[i]=INF; for(int i=1;i<=n;i++){ int x; scanf("%d",&x); sum[i]=sum[i-1]+x; } int flag=0,k=0; for(int i=1;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]);}}

 

转载于:https://www.cnblogs.com/WQHui/p/7575166.html

你可能感兴趣的文章
多张照片拍摄、图片浏览
查看>>
html(5) css
查看>>
Azure Web连接到Azure MySql Db
查看>>
《麻辣江湖》即将上线!
查看>>
Mybatis中mapper.xml文件判断语句中的单双引号问题
查看>>
frameset和frame
查看>>
饥饿的小易(规律,同余大数)
查看>>
ats透明代理
查看>>
PHP 小代码
查看>>
2016/03/16 codes
查看>>
2018年7月21日工作总结
查看>>
Linux shell 命令判断执行语法 ; , && , ||
查看>>
vim代码格式化插件clang-format
查看>>
What does the dot after dollar sign mean in jQuery when declaring variables?
查看>>
windows registry
查看>>
H5 百度一下,你就知道
查看>>
jquery 动画总结(主要指效果函数)
查看>>
使用Dockerfile创建一个tomcat镜像,并运行一个简单war包
查看>>
3. beeGo 自己写Controller 和 请求数据处理
查看>>
20 个 jQuery 分页插件和教程,附带实例
查看>>