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
2010
ACM-ICPC Multi-University Training Contest(7)——Host by HIT 
 
 
 
这个是斜率优化dp的入门题,我看着两篇博客学了半天
传送门:
 
 
第一个是别人推荐的,但上凸下凸好像搞反了。第二个也很不错。
斜率优化一开始学着难,搞懂之后也还好。
 program rrr(input,output);
var
n,m,i,h,t:longint;
q:array[..]of longint;
f,s:array[..]of int64;
function up(j,k:int64):int64;
begin
exit(f[j]-f[k]+sqr(s[j])-sqr(s[k]));
end;
function down(j,k:int64):int64;
begin
exit((s[j]-s[k])<<);
end;
begin
assign(input,'r.in');assign(output,'r.out');reset(input);rewrite(output);
while not eof do
begin
readln(n,m);
s[]:=;
for i:= to n do begin readln(s[i]);s[i]:=s[i]+s[i-]; end;
h:=;t:=;q[]:=;f[]:=;
for i:= to n do
begin
while (h<t) and (up(q[h+],q[h])<=s[i]*down(q[h+],q[h])) do inc(h);
f[i]:=f[q[h]]+sqr(s[i]-s[q[h]])+m;
while (t>h) and (up(i,q[t])*down(q[t],q[t-])<=up(q[t],q[t-])*down(i,q[t])) do dec(t);
inc(t);q[t]:=i;
end;
writeln(f[n]);
end;
close(input);close(output);
end.

这代码一开始没用int64无限WA,后来改了int64才AC了,但我看网上c++代码没开longlong啊,不知道怎么回事。

hdu3507 Print Article(斜率优化入门)(pascal)的更多相关文章

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

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

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

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

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

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

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

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

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

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

  6. hdu3507 Print Article(斜率DP优化)

    Zero has an old printer that doesn't work well sometimes. As it is antique, he still like to use it ...

  7. HDU 3507 Print Article 斜率优化

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

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

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

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

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

  10. 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. 2017-2018-1 20155323《信息安全技术》实验二 Windows口令破解

    2017-2018-1 20155323<信息安全技术>实验二 Windows口令破解 实验目的 了解Windows口令破解原理 对信息安全有直观感性认识 能够运用工具实现口令破解 系统环 ...

  2. High Water Mark 图示

    +---- high water mark of newly created table | V +-------------------------------------------------- ...

  3. 1130: [POI2008]POD Subdivision of Kingdom

    1130: [POI2008]POD Subdivision of Kingdom https://lydsy.com/JudgeOnline/problem.php?id=1130 分析: 有效状态 ...

  4. LVS入门篇(三)之LVS的工作模式和调度算法

    1.NAT模型 (1)原理图: ①.客户端(200.10.10.1)将请求发往前端的负载均衡器(114.100.80.10),请求报文源地址是CIP(客户端IP),后面统称为CIP),目标地址为VIP ...

  5. XAF-物料管理信息工作日志

    前段时间已经开始了第一阶段验收了,客户方并未把重点放在业务流程上面,一直在调整一些界面问题.有点小纠结. 今天要调一下菜单位置. 没修改时,是这样的: 到了列表界面,会多一个全文检索出来. 后来,客户 ...

  6. 180716-Centos时区设置

    使用timedatectl命令同步时间并设置时区 I. timedatactl命令 1. 使用帮助 timedatectl -h 2. 命令示例 2.1 显示系统的当前时间和日期 timedatect ...

  7. Linux内核学习笔记(2)-- 父进程和子进程及它们的访问方法

    Linux系统中,进程之间有一个明显的继承关系,所有进程都是 PID 为1的 init 进程的后代.内核在系统启动的最后阶段启动 init 进程.该进程读取系统的初始化脚本(initscript)并执 ...

  8. asp.net 设计条码code 11的问题

    前一段时间思考了一些条码生成的问题,其实条码也可以说是加密的文件显示. 一个条码首先要有规定 比如code 11 又 1234567890 - 这11个字符组成 而1 又用 5码 表示 "1 ...

  9. 作业 20181016-1 Alpha阶段贡献分配规则

    此作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2244 条件:八位同学,总共80分贡献分(贡献分总数以实际为准),投票方式 ...

  10. Beta周王者荣耀交流协会第三次Scrum会议

    1.立会照片 成员王超,高远博,冉华,王磊,王玉玲,任思佳,袁玥全部到齐. master:王玉玲 2.时间跨度: 2017年11月12日 18:00 — 18:20 ,总计20分钟. 3.地点: 一食 ...