hdu3507 Print Article(斜率优化入门)(pascal)
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.
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.
article.
5
9
5
7
5
ACM-ICPC Multi-University Training Contest(7)——Host by HIT
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)的更多相关文章
- HDU3507 Print Article —— 斜率优化DP
题目链接:https://vjudge.net/problem/HDU-3507 Print Article Time Limit: 9000/3000 MS (Java/Others) Mem ...
- hdu3507 Print Article[斜率优化dp入门题]
Print Article Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)To ...
- [hdu3507 Print Article]斜率优化dp入门
题意:需要打印n个正整数,1个数要么单独打印要么和前面一个数一起打印,1次打印1组数的代价为这组数的和的平方加上常数M.求最小代价. 思路:如果令dp[i]为打印前i个数的最小代价,那么有 dp[i] ...
- HDU3507 Print Article(斜率优化dp)
前几天做多校,知道了这世界上存在dp的优化这样的说法,了解了四边形优化dp,所以今天顺带做一道典型的斜率优化,在百度打斜率优化dp,首先弹出来的就是下面这个网址:http://www.cnblogs. ...
- HDU3507 Print Article (斜率优化DP基础复习)
pid=3507">传送门 大意:打印一篇文章,连续打印一堆字的花费是这一堆的和的平方加上一个常数M. 首先我们写出状态转移方程 :f[i]=f[j]+(sum[i]−sum[j])2 ...
- 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 ...
- 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(斜率优化DP)
题目链接:hdu 3507 Print Article 题意: 每个字有一个值,现在让你分成k段打印,每段打印需要消耗的值用那个公式计算,现在让你求最小值 题解: 设dp[i]表示前i个字符需要消耗的 ...
- Print Article /// 斜率优化DP oj26302
题目大意: 经典题 数学分析 G(a,b)<sum[i]时 a优于b G(a,b)<G(b,c)<sum[i]时 b必不为最优 #include <bits/stdc++.h& ...
- 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 ...
随机推荐
- 20155317 2016-2017-2 《Java程序设计》实验一 Java开发环境的熟悉
20155317 2016-2017-2 <Java程序设计>实验一 Java开发环境的熟悉 实验内容 使用JDK编译.运行简单的Java程序: 使用IDEA 编辑.编译.运行.调试Jav ...
- day8 opencv3 ,没有GMG MOG
Traceback (most recent call last): File , in <module> fgbg = cv2.createBackgroundSubtractorGMG ...
- 4040 EZ系列之奖金 (拓扑)
4040 EZ系列之奖金 时间限制: 1 s 空间限制: 64000 KB 题目等级 : 钻石 Diamond 题目描述 Description 由于无敌的WRN在2015年世界英俊帅 ...
- 深入解析QML引擎, 第2部分: 绑定(Bindings)
原文 QML Engine Internals, Part 2: Bindings 译者注:这个解析QML引擎的文章共4篇,分析非常透彻,在国内几乎没有找到类似的分析,为了便于国内的QT/QML爱好 ...
- JavaWeb(十七)——JSP中的九个内置对象
一.JSP运行原理 每个JSP 页面在第一次被访问时,WEB容器都会把请求交给JSP引擎(即一个Java程序)去处理.JSP引擎先将JSP翻译成一个_jspServlet(实质上也是一个servlet ...
- Linux checksum flag in kernel
net_device->feature | NETIF_F_NO_CSUM: No need to use L4 checksum, it used for loopback device. | ...
- selenium自动化之处理浏览器警告弹窗
有的网站会弹出类似如下图的警告弹窗,你会发现这种弹窗在html源码中怎么也定位不到,接下来将介绍这种弹窗的处理方式. 其实这种弹窗是不属于html的元素的,他是属于浏览器自带的弹窗,所以用定位元素的方 ...
- Unity Lighting - Choosing a Color Space 选择色彩空间(四)
Choosing a Color Space 选择色彩空间 In addition to selecting a rendering path, it’s important to choose ...
- 人脸辨识,用树莓派Raspberry Pi实现舵机云台追踪脸孔
影像辨识作为近年最热门的专业技术之一,广泛用于智慧监视器.车电监控.智慧工厂.生物医疗电子等等:其中,人脸辨识是一个很重要的部分,网络上已经有相当多的资源可供下载使用:于是我们使用舵机云台作为镜头旋转 ...
- 2.1 Oracle之DML的SQL语句之单表查询以及函数
1.SQL简介 对于不同的数据库来说,SQL语句是相通的,关系型数据库都以SQL语句为操作的标准,只是相应的数据库对应的函数不相同. SQL(Structured Query Language,结构化 ...