【HDU3507】Print Article(斜率优化DP)
单调队列DP复出练手题
朴素方程dp[i]=min(dp[j]+(s[i]-s[j-1])^2+m
你懂得
var dp,s:array[..]of int64;
a,q:array[..]of longint;
n,m,i,t,w:longint; function sum(x,y:longint):int64;
begin
exit(s[y]-s[x-]);
end; function clac(j,i:longint):int64;
begin
exit(dp[j]+sqr(sum(j+,i))+m);
end; function cmp(x,y,z:longint):boolean;
var x1,y1,x2,y2:int64;
begin
x1:=dp[x]-dp[y]+sqr(s[x])-sqr(s[y]);
y1:=*(s[x]-s[y]);
x2:=dp[y]-dp[z]+sqr(s[y])-sqr(s[z]);
y2:=*(s[y]-s[z]);
if x1*y2>=x2*y1 then exit(true);
exit(false);
end; begin
assign(input,'1.in'); reset(input);
assign(output,'1.out'); rewrite(output);
while not eof do
begin
readln(n,m);
fillchar(dp,sizeof(dp),);
for i:= to n do readln(a[i]);
s[]:=;
for i:= to n do s[i]:=s[i-]+a[i];
t:=; w:=; q[]:=; dp[]:=;
for i:= to n do
begin
while (w-t>=)and(clac(q[t],i)>=clac(q[t+],i)) do inc(t);
dp[i]:=clac(q[t],i);
while (w-t>=)and cmp(q[w-],q[w],i) do dec(w);
inc(w); q[w]:=i;
end;
writeln(dp[n]);
end;
close(input);
close(output);
end.
【HDU3507】Print Article(斜率优化DP)的更多相关文章
- HDU3507 Print Article —— 斜率优化DP
题目链接:https://vjudge.net/problem/HDU-3507 Print Article Time Limit: 9000/3000 MS (Java/Others) Mem ...
- HDU3507 Print Article(斜率优化dp)
前几天做多校,知道了这世界上存在dp的优化这样的说法,了解了四边形优化dp,所以今天顺带做一道典型的斜率优化,在百度打斜率优化dp,首先弹出来的就是下面这个网址:http://www.cnblogs. ...
- 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基础复习)
pid=3507">传送门 大意:打印一篇文章,连续打印一堆字的花费是这一堆的和的平方加上一个常数M. 首先我们写出状态转移方程 :f[i]=f[j]+(sum[i]−sum[j])2 ...
- 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 ...
- hdu3507Print Article(斜率优化dp)
Print Article Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)To ...
- HDU-3507Print Article 斜率优化DP
学习:https://blog.csdn.net/bill_yang_2016/article/details/54667902 HDU-3507 题意:有若干个单词,每个单词有一个费用,连续的单词组 ...
随机推荐
- Bootstrap历练实例:标签页内的下拉菜单
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...
- C# WPF 粘贴板记录器
工作学习中需要搜索很多资料,有建立文档对遇到过的问题进行记录,但是一来麻烦,二来有些当时认为不重要的事情,也许一段时间后认为是重要的,需要记录的,却又一时找不到,浪费时间做重复的事情.正好借着这个机会 ...
- 设置mysql允许外部连接访问
错误信息: SQL Error (1130): Host ‘192.168.1.88’ is not allowed to connect to this MySQL server 说明所连接的用户帐 ...
- Ubuntu 16.04中安装谷歌Chrome浏览器
1.进入 Ubuntu 16.04 桌面,按下 Ctrl + Alt + t 键盘组合键,启动终端. 2.在终端中,输入以下命令: sudo wget https://repo.fdzh.org/ch ...
- nRF52-PCA10040——Overview
Overview Zephyr applications use the nrf52_pca10040 board configuration to run on the nRF52 Developm ...
- The 2018 ACM-ICPC Chinese Collegiate Programming Contest Fight Against Monsters
#include <iostream> #include <cstdio> #include <cstring> #include <string> # ...
- MIP启发式算法:Variable Neighborhood Decomposition Search
*本文记录和分享学习到的知识,算不上原创. *参考文献见链接. 本文主要简述和VND VNS RINS很相关的vairable neighborhood decomposition search. 目 ...
- BZOJ 2243 染色 树链剖分
题意: 给出一棵树,每个顶点上有个颜色\(c_i\). 有两种操作: C a b c 将\(a \to b\)的路径所有顶点上的颜色变为c Q a b 查询\(a \to b\)的路径上的颜色段数,连 ...
- OpenSSL SNI
网站ssl检测工具 https://www.ssllabs.com/ssltest/analyze.html?d=gggl.houseoflux.com.cn https://myssl.com/ ...
- C++ 获取网页源码码的操作
#include <stdio.h>#include <windows.h>#include <wininet.h>#pragma comment(lib,&quo ...