dp斜率优化 Hdu 3507(Print Article)详细题解

这是一篇关于Hdu 3507 Print Article问题的详细解题博客,介绍了如何利用动态规划和斜率优化解决这个问题。通过分析打印机的成本和每行单词数限制,建立DP模型并转换为求解固定斜率下最小值的问题,利用单调队列维护凸包实现优化。博客提供了样例输入和输出,并附带了几道类似练习题的链接。
摘要由CSDN通过智能技术生成

题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=3507

累加器传送门:

http://blog.csdn.net/noiau/article/details/71775000

题目:

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.

输入:

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.

输出:

A single number, meaning the mininum cost to print the article.

样例输入:

5 5
5
9
5
7
5

样例输出:

230


这篇博客本来写好了的…然后没有保存一下子不小心把浏览器关了…所以重新写一遍吧


分析题目

分割出最小值

所以可以想到一个很简单的dp转移方程

dp[i]=min(dp[i],dp[j]+(cnt[i]-cnt[j])^2+M);

(伪代码)


其中dp[i]表示把前i个数分解成若干段所能获得的最小值,可以枚举j 然后把i到j切成一段需要花费(cnt[i]-cnt[j])^2和一个M

cnt数组维护的是前缀和

把括号打开,M可以直接拿出来

dp[i]=min(dp[i],dp[j]+cnt[i]^2-2*cnt[i]*cnt[j]+cnt[j]^2)+M

M就扔了,最后再加上去,因为M是个常量,无论怎么决策都不影响M的值


而对于一个i来说,cnt[i]^2也一定是确定的

所以再把cnt[i]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值