DP(斜率优化):HDU 3507 Print Article
Print Article
Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 8199 Accepted Submission(s): 2549
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.
5
9
5
7
5
#include <iostream>
#include <cstdio>
using namespace std;
const int maxn=;
long long f[maxn],s[maxn];
int q[maxn];
int main()
{
int n,m,front,back;
while(~scanf("%d%d",&n,&m))
{
s[]=f[]=;
for(int i=;i<=n;i++)scanf("%d",&s[i]);
for(int i=;i<=n;i++)s[i]+=s[i-]; front=;back=;
q[front]=; for(int i=;i<=n;i++)
{
while(front<back-&&(f[q[front+]]+s[q[front+]]*s[q[front+]])-(f[q[front]]+s[q[front]]*s[q[front]])<=*s[i]*(s[q[front+]]-s[q[front]])) front++; f[i]=f[q[front]]+(s[i]-s[q[front]])*(s[i]-s[q[front]])+m; while(front<back-&&(s[q[back-]]-s[q[back-]])*((f[i]+s[i]*s[i])-(f[q[back-]]+s[q[back-]]*s[q[back-]]))<=(s[i]-s[q[back-]])*((f[q[back-]]+s[q[back-]]*s[q[back-]])-(f[q[back-]]+s[q[back-]]*s[q[back-]])))back--;
q[back++]=i;
}
printf("%lld\n",f[n]);
}
return ;
}
DP(斜率优化):HDU 3507 Print Article的更多相关文章
- hdu 3507 Print Article(斜率优化DP)
题目链接:hdu 3507 Print Article 题意: 每个字有一个值,现在让你分成k段打印,每段打印需要消耗的值用那个公式计算,现在让你求最小值 题解: 设dp[i]表示前i个字符需要消耗的 ...
- HDU 3507 [Print Article]DP斜率优化
题目大意 给定一个长度为\(n(n \leqslant 500000)\)的数列,将其分割为连续的若干份,使得 $ \sum ((\sum_{i=j}^kC_i) +M) $ 最小.其中\(C_i\) ...
- HDU 3507 Print Article(DP+斜率优化)
Print Article Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) ...
- HDU 3507 Print Article(斜率优化DP)
题目链接 题意 : 一篇文章有n个单词,如果每行打印k个单词,那这行的花费是,问你怎么安排能够得到最小花费,输出最小花费. 思路 : 一开始想的简单了以为是背包,后来才知道是斜率优化DP,然后看了网上 ...
- HDU 3507 - Print Article - [斜率DP]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3507 Zero has an old printer that doesn't work well s ...
- HDU 3507 Print Article 斜率优化
Print Article Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)To ...
- HDU 3507 Print Article(斜率优化)
显然的斜率优化模型 但是单调队列维护斜率单调性的时候出现了莫名的锅orz 代码 #include <cstdio> #include <algorithm> #include ...
- HDU 3507 Print Article(斜率优化推导)
$dp$,斜率优化. 第一次做斜率优化的题目,看了一些题解,自己总结一下. 这题是说有$n$个数字,可以切成任意段,每一段的费用是这一段数字的和平方加上$M$.问最小费用是多少. 设$dp[i]$为$ ...
- 斜率优化板题 HDU 3507 Print Article
题目大意:输出N个数字a[N],输出的时候可以连续的输出,每连续输出一串,它的费用是 "这串数字和的平方加上一个常数M".n<=500000 我们设dp[i]表示输出到i的时 ...
随机推荐
- 第四篇:python 高级之面向对象初级
python 高级之面向对象初级 python 高级之面向对象初级 本节内容 类的创建 类的构造方法 面向对象之封装 面向对象之继承 面向对象之多态 面向对象之成员 property 1.类的创建 ...
- ASP.NET Webform或者ASP.NET MVC站点部署到IIS下,默认情况下.json文件是不能被访问的,如果请求访问.json文件,则会出现找不到文件的404错误提示
解决方法 <system.webServer> <staticContent> <remove fileExtension=".woff" /> ...
- Android布局管理器(贞布局)
贞布局有FrameLayout所代表,它直接继承了ViewGroup组建 贞布局为每个加入其中的组件创建一个空白区域(一帧),所以每个子组件占用一帧,这些贞都会根据gravity属性执行自动对齐 贞布 ...
- PHP算法 《图》 之 理论基础
转载自:http://www.cnblogs.com/skywang12345/p/3691463.html Ⅰ 图的基本概念 1. 图的定义 定义:图(graph)是由一些点(vertex)和这些点 ...
- HTML页面中启用360浏览器极速模式
今天做页面突然遇到浏览器一直在兼容模式下运行,体验不好,通过查询文档,在<head>中加入<meta name="renderer" content=" ...
- opencv安装及学习资料
第一次装时win7+VS2010+opencv3.0,结果不成功,原因解压出来的没有vc10,可能新版本不在支持vc的旧版本了.所以换了VS2013+opencv3.0,比较经典的安装时VS2010+ ...
- HDU 3359 Kind of a Blur(高斯消元)
题意: H * W (W,H <= 10) 的矩阵A的某个元素A[i][j],从它出发到其他点的曼哈顿距离小于等于D的所有值的和S[i][j]除上可达点的数目,构成了矩阵B.给定矩阵B,求矩阵A ...
- chromedriver release note
----------ChromeDriver v2.25 (2016-10-25)---------- Supports Chrome v53-55 Resolved issue 1547: Chro ...
- how to use a xml_id in field domain
"[('parent_id','child_of', %(other_module.xml_id)d)]"
- Python Tutorial 学习(十)-- Brief Tour of the Standard Library
10.1. Operating System Interface os库 import os os.getcwd() # Return the current working directory 'C ...