博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Print Article hdu 3507 一道斜率优化DP 表示是基础题,但对我来说很难
阅读量:6567 次
发布时间:2019-06-24

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

Print Article

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

Total Submission(s): 4990    Accepted Submission(s): 1509

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
 
 
1 #include 
2 #include
3 #include
4 #include
5 #include
6 using namespace std; 7 int a[600000],sum[600000],h[600000],dp[600000],m; 8 int getup(int j,int k) 9 {10 return dp[j]+sum[j]*sum[j]-dp[k]-sum[k]*sum[k];11 }12 int getdown(int j,int k)13 {14 return ((sum[j]-sum[k])<<1);15 }16 int getdp(int i,int j)17 {18 return dp[j]+m+(sum[i]-sum[j])*(sum[i]-sum[j]);19 }20 int main()21 {22 int n,i,head,tail;23 while(~scanf("%d%d",&n,&m))24 {25 memset(h,0,sizeof(h));26 sum[0]=a[0]=0;27 for(i=1; i<=n; i++)28 scanf("%d",&a[i]),sum[i]=sum[i-1]+a[i];29 head=tail=0;30 h[tail++]=0;31 for(i=1;i<=n;i++)32 {33 while(head+1
<=sum[i]*getdown(h[head+1],h[head]))34 head++;35 dp[i]=getdp(i,h[head]);36 while(head+1
=getup(i,h[tail-1])*getdown(h[tail-1],h[tail-2]))37 tail--;38 h[tail++]=i;39 }40 cout<
<
View Code

 

转载于:https://www.cnblogs.com/ERKE/p/3833612.html

你可能感兴趣的文章
mysql数据库从删库到跑路之mysql完整性约束
查看>>
简单的Writer和Reader
查看>>
zabbix学习(四)IT_Service管理
查看>>
linux 下的lamp的简单安装
查看>>
Typescript 其实就想排个序和枚举取数
查看>>
virt-manager管理kvm
查看>>
python测试rabbitmq的消息收发
查看>>
熊猫直播Rancho发布系统构建之路
查看>>
DbUtils
查看>>
mac 环境下 制作windows系统U盘启动盘
查看>>
JMeter基础之一个简单的性能测试
查看>>
让批处理运行不显示窗口的两个方法
查看>>
江苏省环保厅数据中心同城灾备建设项目
查看>>
hadoop 安全模式
查看>>
我的友情链接
查看>>
新手教程:用.htaccess实现二级域名功能
查看>>
How to attack a windows domain
查看>>
安装完Arch后,要安装的软件
查看>>
洛谷——P2035 iCow
查看>>
空类,虚函数类,虚继承类的空间大小
查看>>