【HDU】3507Print 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
翻译
打印文章
时间限制:9000/3000 MS(Java /其他)
内存限制:131072/65536 K(Java /其他)
问题描述
Zero的旧打印机有时无法正常工作。由于是古董,他仍然喜欢用它来印刷物品。但是它太旧了,无法长时间工作,它肯定会磨损,因此Zero使用成本来评估该程度。
有一天,零希望打印一篇包含N个单词的文章,而每个单词i的打印成本为Ci。而且,Zero知道在一行中打印k个字会花费
M是一个常数。
现在,Zero想要知道最低成本以便完美地布置商品。
输入
有很多测试用例。对于每个测试用例,第一行中都有两个数字N和M(0≤n≤500000,0≤M≤1000)。然后,在接下来的2到N + 1行中有N个数字。输入由EOF终止。
输出
一个数字,表示打印文章的最低费用。
样本输入
5 5
5
9
5
7
5
样本输出
230
思路
题意很清楚,就是输出序列a[n],每连续输出的费用是连续输出的数字和的平方加上常数M
让我们求这个费用的最小值。
设dp[i]表示输出前i个的最小费用,那么有如下的DP方程:
dp[i]= min{ dp[j]+(sum[i]-sum[j])^2 +M } 0<j<i