BZOJ1911 [Apio2010]特别行动队 【斜率优化】
1911: [Apio2010]特别行动队
Time Limit: 4 Sec Memory Limit: 64 MB
Submit: 5005 Solved: 2455
[Submit][Status][Discuss]
Description

Input

Output

Sample Input
-1 10 -20
2 2 3 4
Sample Output
HINT

一定要好好纪念一下QAQ,本蒟蒻第一次自己推出斜率优化dp
有点模糊惹。。将就一下【捂脸】
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define eps 1e-9
#define LL long long int
#define REP(i,n) for (int i = 1; i <= (n); i++)
#define fo(i,x,y) for (int i = (x); i <= (y); i++)
#define Redge(u) for (int k = head[u]; k != -1; k = edge[k].next)
using namespace std;
const int maxn = 1000005,maxm = 100005,INF = 1000000000;
inline int read(){
int out = 0,flag = 1;char c = getchar();
while (c < 48 || c > 57) {if (c == '-') flag = -1; c = getchar();}
while (c >= 48 && c <= 57) {out = out * 10 + c - 48; c = getchar();}
return out * flag;
}
int n,a,b,c,q[maxn],head,tail;
LL sum[maxn],f[maxn];
inline double slope(int u,int v){
double y1 = f[u] + a * sum[u] * sum[u] - b * sum[u],y2 = f[v] + a * sum[v] * sum[v] - b * sum[v];
return (y1 - y2) / (sum[u] - sum[v]);
}
inline LL g(LL x){
return a * x * x + b * x + c;
}
inline LL getf(int i,int j){
return f[j] + g(sum[i] - sum[j]);
}
int main()
{
n = read(); a = read(); b = read(); c = read();
REP(i,n) sum[i] = sum[i - 1] + read();
head = tail = 0;
for (int i = 1; i <= n; i++){
while (head < tail && slope(q[head],q[head + 1]) + eps > 2 * a * sum[i])
head++;
f[i] = getf(i,q[head]);
while (head < tail && slope(q[tail],q[tail - 1]) < slope(i,q[tail]) + eps)
tail--;
q[++tail] = i;
}
cout << f[n] << endl;
return 0;
}
BZOJ1911 [Apio2010]特别行动队 【斜率优化】的更多相关文章
- bzoj1911[Apio2010]特别行动队 斜率优化dp
1911: [Apio2010]特别行动队 Time Limit: 4 Sec Memory Limit: 64 MBSubmit: 5057 Solved: 2492[Submit][Statu ...
- bzoj1911 [Apio2010]特别行动队——斜率优化DP
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1911 相当明显的斜率优化,很好做: 注意slp里面要有(double),以免出现精度问题. ...
- [Bzoj1911][Apio2010]特别行动队(斜率优化)
题目链接 斜率优化的经典模型,将序列分成若干段,每段有一个权值计算方法,求权值和最大/小 暴力的dp $O(n^{2})$ dp[i]为1-i的序列的最优解.sum[i]为前缀和,$D(i)=ax^{ ...
- [APIO2010]特别行动队 --- 斜率优化DP
[APIO2010]特别行动队 题面很直白,就不放了. 太套路了,做起来没点感觉了. \(dp(i)=dp(j)+a*(s(i)-s(j))^{2}+b*(s(i)-s(j))+c\) 直接推出一个斜 ...
- BZOJ 1911: [Apio2010]特别行动队 [斜率优化DP]
1911: [Apio2010]特别行动队 Time Limit: 4 Sec Memory Limit: 64 MBSubmit: 4142 Solved: 1964[Submit][Statu ...
- bzoj 1911: [Apio2010]特别行动队 -- 斜率优化
1911: [Apio2010]特别行动队 Time Limit: 4 Sec Memory Limit: 64 MB Description Input Output Sample Input 4 ...
- APIO2010 特别行动队 & 斜率优化DP算法笔记
做完此题之后 自己应该算是真正理解了斜率优化DP 根据状态转移方程$f[i]=max(f[j]+ax^2+bx+c),x=sum[i]-sum[j]$ 可以变形为 $f[i]=max((a*sum[j ...
- 【BZOJ1911】[Apio2010]特别行动队 斜率优化DP
想了好久啊....——黑字为第一次更新.——这里是第二次更新,维护上下凸包据题而论,第一种方法是化式子的方法,需要好的化式子的方法,第二种是偏向几何,十分好想,纯正的维护凸包的方法,推荐. 用了我感觉 ...
- 洛谷P3628 [APIO2010]特别行动队 斜率优化
裸题,注意队列下标不要写错 Code: #include<cstdio> #include<algorithm> #include<cmath> using nam ...
随机推荐
- List和Turple
List 格式:classmates = ['Michael', 'Bob', 'Tracy'] 读取list长度用:len(classmetes) 索引:索引正向从0开始,逆向从-1开始 在末尾增加 ...
- Django学习总结②----关系运算与F,Q关系
关联mysql步骤: 第一步:下载pymysql:pip install pymysql 第二步:在工程目录下的init文件下,将pymysql引入 import pymysql pymysql.in ...
- Stunnel客户端安装和配置
声明:本文并非原创,转自华为云帮助中心的分布式缓存服务(DCS)的用户指南. 本文以公网访问华为云分布式缓存服务的Redis缓存为示例,介绍Stunnel客户端在各操作系统下的安装和配置. Stunn ...
- mvc中actionresult的返回值类型
以前一直没注意actionresult都能返回哪些类型的类型值(一直用的公司的内部工具类初始化进行返回的),今天跟大家分享一下(也是转载的别人的日志qaq). 首先我们了解一下对action的要求: ...
- LeetCode - 13. Roman to Integer - 思考if-else与switch的比较 - ( C++ ) - 解题报告
1.题目: 原题:Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range ...
- 安装sqoop 1.99.4
参考http://sqoop.apache.org/docs/1.99.4/Installation.html 1.简介 sqoop2分为server和client两部分.server作为maprde ...
- [leetcode-666-Path Sum IV]
If the depth of a tree is smaller than 5, then this tree can be represented by a list of three-digit ...
- NYOJ 35 表达式求值(逆波兰式求值)
http://acm.nyist.net/JudgeOnline/problemset.php?typeid=4 NYOJ 35 表达式求值(逆波兰式求值) 逆波兰式式也称后缀表达式. 一般的表达式求 ...
- “Hello world!”团队第三周贡献分规则
一.贡献规则制定: (1)基础分:9 , 9 , 8 , 7 , 7 , 7 , 6(按在本次编程中承担模块的重要度制定,某一模块重要度的认定通过组内开会讨论决定) (2)会议分:每人没出勤一次会议记 ...
- JavaWeb基础 - 会话
会话概述 什么是会话 简单的理解:用户打开浏览器,点击多个超链接,访问Web服务器上多个资源,然后关闭浏览器,整个过程称之为一次会话. 需要解决的问题 每个用户在使用浏览器与服务器会话的过程中,会产生 ...