hdu3507 斜率dp
来源:互联网 发布:网络平台的商业模式 编辑:程序博客网 时间:2024/06/05 18:57
Print Article
Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)Total Submission(s): 14216 Accepted Submission(s): 4414
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.
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 559575
Sample Output
230#include<bits/stdc++.h>using namespace std;typedef long long LL;int m;LL sum[501111];LL dp[501111];int q[1001111];LL getup(int i,int j){ return dp[i]+sum[i]*sum[i]-(dp[j]+sum[j]*sum[j]);}LL getdown(int i,int j){ return 2*(sum[i]-sum[j]);}LL getdp(int i,int j){ return dp[i]+m+(sum[j]-sum[i])*(sum[j]-sum[i]);}int main(){ int n; while(scanf("%d%d",&n,&m)!=EOF) { sum[0]=dp[0]=0; for(int i=1;i<=n;i++) { LL a; scanf("%lld",&a); sum[i]=sum[i-1]+a; } int head=0,tail=0; q[tail++]=0; for(int i=1;i<=n;i++) { while(head+1<tail&&getup(q[head+1],q[head])<=sum[i]*getdown(q[head+1],q[head])) head++; dp[i]=getdp(q[head],i); while(head+1<tail&&getup(i,q[tail-1])*getdown(q[tail-1],q[tail-2])<=getup(q[tail-1],q[tail-2])*getdown(i,q[tail-1])) tail--; q[tail++]=i; } printf("%lld\n",dp[n]); } return 0;}http://www.cnblogs.com/kuangbin/archive/2012/08/26/2657650.html
阅读全文
0 0
- hdu3507斜率优化dp
- hdu3507 斜率优化dp
- 斜率优化DP(hdu3507)
- hdu3507(斜率dp)
- 斜率优化dp:HDU3507
- hdu3507 斜率dp
- HDU3507(dp + 斜率优化dp)
- hdu3507 斜率优化dp入门
- hdu3507之斜率优化DP入门
- HDU3507--Print Article(斜率优化DP)
- [HDU3507]Print Article(斜率优化dp)
- hdu3507 Print Article(斜率优化dp)
- hdu3507 Print Article(斜率优化dp)
- hdu3507 Print Article DP+斜率优化
- 【HDU3507】Print Article-DP斜率优化入门
- [hdu3507] Print Article DP斜率优化入门
- 【HDU3507】【斜率优化DP】Print Article题解
- #HDU3507#Print Article(DP+斜率优化)
- toast和menu的使用
- Hibernate与mybatis的区别
- 贪心算法总结
- 信息论实验-通信系统仿真(C++)
- 6位36位进制转十进制加一,十进制转36位进制
- hdu3507 斜率dp
- Hadoop java 远程操作注意 Configuration
- Python random模块
- 彻底解决了Intellij IDEA 2017.2 中文无法输入及中英文没法自由切换的问题
- Android学习-解读shape文件和selector文件
- Linux下使用caffe进行图像分类
- python用matplotlib画图例子(2)
- [NLP]如何打造一个Chatbot
- MySQL链接服务器权限配置