Print Article

Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 12824    Accepted Submission(s):
3967

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:  3506 3501 3504 3505 3498 
 
斜率优化dp学习:http://www.cnblogs.com/ka200812/archive/2012/08/03/2621345.html
 
#include<iostream>
#include<cstdio>
#include<cstring> #define N 500005 using namespace std;
int dp[N],q[N],sum[N];
int head,tail,n,m; int get_dp(int i,int j)
{
return dp[j]+m+(sum[i]-sum[j])*(sum[i]-sum[j]);
} int get_up(int j,int k)
{
return dp[j]+sum[j]*sum[j]-(dp[k]+sum[k]*sum[k]);
} int get_down(int j,int k)
{
return *(sum[j]-sum[k]);
} int main()
{
while(scanf("%d%d",&n,&m)==)
{
for(int i=;i<=n;i++) scanf("%d",&sum[i]);
sum[]=dp[]=;head=tail=;
for(int i=;i<=n;i++) sum[i]+=sum[i-];
q[tail++]=;
for(int i=;i<=n;i++)
{
while(head+<tail && get_up(q[head+],q[head])<=sum[i]*get_down(q[head+],q[head]))
head++;
dp[i]=get_dp(i,q[head]);
while(head+<tail && get_up(i,q[tail-])*get_down(q[tail-],q[tail-])<=get_up(q[tail-],q[tail-])*get_down(i,q[tail-]))
tail--;
q[tail++]=i;
}
printf("%d\n",dp[n]);
}
return ;
}

hdu3507Print Article(斜率优化dp)的更多相关文章

  1. HDU-3507Print Article 斜率优化DP

    学习:https://blog.csdn.net/bill_yang_2016/article/details/54667902 HDU-3507 题意:有若干个单词,每个单词有一个费用,连续的单词组 ...

  2. HDU3507 Print Article(斜率优化dp)

    前几天做多校,知道了这世界上存在dp的优化这样的说法,了解了四边形优化dp,所以今天顺带做一道典型的斜率优化,在百度打斜率优化dp,首先弹出来的就是下面这个网址:http://www.cnblogs. ...

  3. hdu 3507 Print Article(斜率优化DP)

    题目链接:hdu 3507 Print Article 题意: 每个字有一个值,现在让你分成k段打印,每段打印需要消耗的值用那个公式计算,现在让你求最小值 题解: 设dp[i]表示前i个字符需要消耗的 ...

  4. hdu3507 Print Article[斜率优化dp入门题]

    Print Article Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)To ...

  5. HDU3507 Print Article —— 斜率优化DP

    题目链接:https://vjudge.net/problem/HDU-3507 Print Article Time Limit: 9000/3000 MS (Java/Others)    Mem ...

  6. [hdu3507 Print Article]斜率优化dp入门

    题意:需要打印n个正整数,1个数要么单独打印要么和前面一个数一起打印,1次打印1组数的代价为这组数的和的平方加上常数M.求最小代价. 思路:如果令dp[i]为打印前i个数的最小代价,那么有 dp[i] ...

  7. Print Article /// 斜率优化DP oj26302

    题目大意: 经典题 数学分析 G(a,b)<sum[i]时 a优于b G(a,b)<G(b,c)<sum[i]时 b必不为最优 #include <bits/stdc++.h& ...

  8. HDU3507 Print Article (斜率优化DP基础复习)

    pid=3507">传送门 大意:打印一篇文章,连续打印一堆字的花费是这一堆的和的平方加上一个常数M. 首先我们写出状态转移方程 :f[i]=f[j]+(sum[i]−sum[j])2 ...

  9. hdu 3507 Print Article —— 斜率优化DP

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=3507 设 f[i],则 f[i] = f[j] + (s[i]-s[j])*(s[i]-s[j]) + m ...

随机推荐

  1. Django - 基于orm实现用户增删改查

    1.基于orm实现用户新增 user_info.html中,增加代码: views.py中,在原user_info函数中,增加判断代码: 备注:最后一句,可以通过return redirect 实现, ...

  2. What is the difference between rhel 6 and rhel7

    What is the difference between rhel 6 and rhel7 difference rhel 6 RHEL 7 release date 10 NOV 2010 as ...

  3. [luogu2154 SDOI2009] 虔诚的墓主人(树状数组+组合数)

    传送门 Solution 显然每个点的权值可以由当前点上下左右的树的数量用组合数\(O(1)\)求出,但这样枚举会T 那么我们考虑一段连续区间,对于一行中两个常青树中间的部分左右树的数量一定,我们可用 ...

  4. linux安装openjdk

    使用yum查找jdk: yum search java | grep jdk 执行安装命令:yum install java-1.8.0-openjdk

  5. Linux 环境下安装python相关

    目录 Linux 环境下安装python相关 linux软件包管理工具之yum工具(如同pip3工具) yum源理解 下载阿里云的.repo仓库文件 ,放到/etc/yum.repos.d/ yum安 ...

  6. 2、ceph-deploy之配置使用RBD

    说明 部署完ceph集群(active+clean状态)之后, 我们来实践下ceph block device(即RBD或RADOS block device). 我们需要在一台新的client节点上 ...

  7. [luoguP2870] [USACO07DEC]最佳牛线,黄金Best Cow Line, Gold(后缀数组)

    传送门 数据小的话贪心就行. 可以把这个串翻转再接到后面,再求后缀数组,求出 rank 数组就很简单了. ——代码 #include <cstdio> #include <iostr ...

  8. python实现字符串之间的映射

    类似于凯撒密码一样的加密 # *-* coding=utf-8 *-* import string intab = string.lowercase outtab = 'qwertyuiopasdfg ...

  9. [bzoj3676]回文串[后缀数组+Manacher]

    后缀数组+Manacher #include <iostream> #include <cstdio> #include <cstdlib> #include &l ...

  10. [bzoj3339]Rmq Problem||[bzoj3585]mex_线段树

    Rmq Problem bzoj-3339||mex bzoj-3585 题目大意:给定一个长度为n的数列a,多次讯问区间l,r中最小的不属于集合{$A_l,A_{l+1}...A_r$}的非负整数. ...