题意

题目链接

Sol

裸的斜率优化,注意推导过程中的符号问题。

#include<bits/stdc++.h>
#define Pair pair<int, int>
#define MP(x, y) make_pair(x, y)
#define fi first
#define se second
#define int long long
#define LL long long
#define Fin(x) {freopen(#x".in","r",stdin);}
#define Fout(x) {freopen(#x".out","w",stdout);}
using namespace std;
const int MAXN = 1e6 + 10, mod = 1e9 + 7, INF = 6e18 + 10;
const double eps = 1e-9;
template <typename Y> inline void chmin(Y &a, Y b){a = (a < b ? a : b);}
template <typename Y> inline void chmax(Y &a, Y b){a = (a > b ? a : b);}
template <typename Y> inline void debug(Y a){cout << a << '\n';}
template <typename Y> inline LL sqr(Y x){return 1ll * x * x;}
int add(int x, int y) {if(x + y < 0) return x + y + mod; return x + y >= mod ? x + y - mod : x + y;}
void add2(int &x, int y) {if(x + y < 0) x = x + y + mod; else x = (x + y >= mod ? x + y - mod : x + y);}
int mul(int x, int y) {return 1ll * x * y % mod;}
inline int read() {
char c = getchar(); int x = 0, f = 1;
while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
int N, S[MAXN], A, B, C, f[MAXN], q[MAXN];
int F(int x) {
return A * sqr(x) + B * x + C;
}
double Y(int x) {
return A * sqr(S[x]) - B * S[x] + f[x];
}
double X(int x) {
return S[x];
}
double slope(int a, int b) {
// debug((Y(b) - Y(a)) / (X(b) - X(a)));
return double(Y(b) - Y(a)) / (X(b) - X(a));
}
signed main() {
N = read(); A = read(); B = read(); C = read();
for(int i = 1; i <= N; i++) S[i] = S[i - 1] + read();
q[1] = 0;
for(int i = 1, h = 1, t = 1; i <= N; i++) {
while(h < t && slope(q[h], q[h + 1]) > 2 * A * S[i]) h++;
f[i] = f[q[h]] + F(S[i] - S[q[h]]);
//printf("%d\n", q[h]);
while(h < t && slope(q[t - 1], q[t]) < slope(q[t], i)) t--;
q[++t] = i;
}
cout << f[N];
return 0;
}
/*
7
-1 160 -2000
14 82 61 85 41 10 34
*/

BZOJ1911: [Apio2010]特别行动队(dp 斜率优化)的更多相关文章

  1. 【BZOJ-1911】特别行动队 DP + 斜率优化

    1911: [Apio2010]特别行动队 Time Limit: 4 Sec  Memory Limit: 64 MBSubmit: 3478  Solved: 1586[Submit][Statu ...

  2. BZOJ 1911: [Apio2010]特别行动队( dp + 斜率优化 )

    sum为战斗力的前缀和 dp(x) = max( dp(p)+A*(sumx-sump)2+B*(sumx-sump)+C )(0≤p<x) 然后斜率优化...懒得写下去了... ------- ...

  3. BZOJ1911 [Apio2010]特别行动队 【斜率优化】

    1911: [Apio2010]特别行动队 Time Limit: 4 Sec  Memory Limit: 64 MB Submit: 5005  Solved: 2455 [Submit][Sta ...

  4. 2018.09.07 bzoj1911: [Apio2010]特别行动队(斜率优化dp)

    传送门 斜率优化dp经典题. 题目中说的很清楚,设f[i]表示前i个数分配出的最大值. 那么有: f[i]=max(f[j]+A∗(sum[i]−sum[j])2+B∗(sum[i]−sum[j])+ ...

  5. BZOJ1911 [Apio2010]特别行动队 - 动态规划 - 斜率优化

    欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 UPD(2018-04-01):用Latex重打了公式…… 题意概括 把一个整数序列划分成任意连续的段,使得划分出 ...

  6. [bzoj1911][Apio2010特别行动队] (动态规划+斜率优化)

    Description Input Output Sample Input - - Sample Output HINT Solution 斜率优化动态规划 首先易得出这样的一个朴素状态转移方程 f[ ...

  7. bzoj 1911 [Apio2010]特别行动队(斜率优化+DP)

    1911: [Apio2010]特别行动队 Time Limit: 4 Sec  Memory Limit: 64 MBSubmit: 3191  Solved: 1450[Submit][Statu ...

  8. P3628 [APIO2010]特别行动队(斜率优化dp)

    P3628 [APIO2010]特别行动队 设$s[i]$为战斗力前缀和 显然我们可以列出方程 $f[i]=f[j]+a*(s[i]-s[j])^{2}+b*(s[i]-s[j])+c$ $f[i]= ...

  9. 【BZOJ 1191】 [Apio2010]特别行动队 (斜率优化)

    dsy1911: [Apio2010]特别行动队 [题目描述] 有n个数,分成连续的若干段,每段的分数为a*x^2+b*x+c(a,b,c是给出的常数),其中x为该段的各个数的和.求如何分才能使得各个 ...

随机推荐

  1. jsp页面,jstl标签中的数据在<%%>java中使用

    可参考jsp的API隐式对象.. 这部分数据其实被保存在page域中,但jsp中如果使用java代码需要在特定的标签中<%%>,在这个标签中可使用的只有pageContext对象,所以可以 ...

  2. 《JAVA与模式》之桥梁模式

    在阎宏博士的<JAVA与模式>一书中开头是这样描述桥梁(Bridge)模式的: 桥梁模式是对象的结构模式.又称为柄体(Handle and Body)模式或接口(Interface)模式. ...

  3. Swinject 源码框架(三):Object Scopes

    Object Scopes 指定了生成的实例在系统中是如何被共享的. 如何指定 scope container.register(Animal.self) { _ in Cat() } .inObje ...

  4. Go语言学习笔记(3)——分支、循环结构

    1 条件语句: if, else if, else   特殊用法:判断num是奇是偶:其中局部变量num只能在该if...else语句中使用! if num := 10; num % 2 == 0 { ...

  5. IIS 8 配置错误

    1) ProtocolException: The remote server returned an unexpected response: (405) Method Not Allowed Th ...

  6. 【数组】Find Peak Element

    题目: A peak element is an element that is greater than its neighbors. Given an input array where num[ ...

  7. WPF中触发器(Trigger、DataTrigger)使用动画最简单的方式EnterActions和ExitsActions

    1.当鼠标移入后执行某个动画: <Style TargetType="{x:Type StackPanel}"> <Setter Property="R ...

  8. 生成类似于MongoDB产生的ObjectId

    package com.jt.boot.utils; import com.google.common.base.Objects; import java.net.NetworkInterface; ...

  9. DateUtils 通用类

    package com.egaoqi.util; import org.apache.commons.lang3.time.DateFormatUtils; import java.text.Pars ...

  10. gitlab+jenkins+hook代码自动构建发布上线

    Gitlab+Jenkins+Hook 1.gitlab和jenkins的安装见: http://www.cnblogs.com/cuishuai/p/7544663.html http://www. ...