1911: [Apio2010]特别行动队

Time Limit: 4 Sec  Memory Limit: 64 MB

Submit: 5005  Solved: 2455

[Submit][Status][Discuss]

Description

Input

Output

Sample Input

4

-1 10 -20

2 2 3 4

Sample Output

9

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]特别行动队 【斜率优化】的更多相关文章

  1. bzoj1911[Apio2010]特别行动队 斜率优化dp

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

  2. bzoj1911 [Apio2010]特别行动队——斜率优化DP

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1911 相当明显的斜率优化,很好做: 注意slp里面要有(double),以免出现精度问题. ...

  3. [Bzoj1911][Apio2010]特别行动队(斜率优化)

    题目链接 斜率优化的经典模型,将序列分成若干段,每段有一个权值计算方法,求权值和最大/小 暴力的dp $O(n^{2})$ dp[i]为1-i的序列的最优解.sum[i]为前缀和,$D(i)=ax^{ ...

  4. [APIO2010]特别行动队 --- 斜率优化DP

    [APIO2010]特别行动队 题面很直白,就不放了. 太套路了,做起来没点感觉了. \(dp(i)=dp(j)+a*(s(i)-s(j))^{2}+b*(s(i)-s(j))+c\) 直接推出一个斜 ...

  5. BZOJ 1911: [Apio2010]特别行动队 [斜率优化DP]

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

  6. bzoj 1911: [Apio2010]特别行动队 -- 斜率优化

    1911: [Apio2010]特别行动队 Time Limit: 4 Sec  Memory Limit: 64 MB Description Input Output Sample Input 4 ...

  7. APIO2010 特别行动队 & 斜率优化DP算法笔记

    做完此题之后 自己应该算是真正理解了斜率优化DP 根据状态转移方程$f[i]=max(f[j]+ax^2+bx+c),x=sum[i]-sum[j]$ 可以变形为 $f[i]=max((a*sum[j ...

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

    想了好久啊....——黑字为第一次更新.——这里是第二次更新,维护上下凸包据题而论,第一种方法是化式子的方法,需要好的化式子的方法,第二种是偏向几何,十分好想,纯正的维护凸包的方法,推荐. 用了我感觉 ...

  9. 洛谷P3628 [APIO2010]特别行动队 斜率优化

    裸题,注意队列下标不要写错 Code: #include<cstdio> #include<algorithm> #include<cmath> using nam ...

随机推荐

  1. 即刻开始使用Kotlin开发Android的12个原因(KAD 30)

    作者:Antonio Leiva 时间:Jul, 11, 2017 原文链接:https://antonioleiva.com/reasons-kotlin-android/ 这组文章已到最后了,它们 ...

  2. 第六阶段·数据库MySQL及NoSQL实践第1章·章节一MySQL数据库

    01 课程介绍 02 数据库管理系统介绍 03 MySQL安装方式介绍及源码安装 04 MySQL安装后的基本配置 05 MySQL体系结构-服务器.客户端模型 06 MySQL体系结构-实例.连接层 ...

  3. 前端开发工程师 - 01.页面制作 - 第1章.Photoshop切图

    第1章--Photoshop切图 工具.面板.视图 什么是切图? 1. 从设计稿(.psd)中切出网络素材,如按钮.图标.logo.背景图等 2. 编写代码,在代码中使用图片,生成静态页面 --给网页 ...

  4. (Python爬虫05)完善的爬虫学习大纲

  5. HDU - 6440(费马小定理)

    链接:HDU - 6440 题意:重新定义加法和乘法,使得 (m+n)^p = m^p + n^p 成立,p是素数.,且satisfied that there exists an integer q ...

  6. python 终极篇 --- django 路由系统

                          URL配置                        基本格式: from django.conf.urls import url urlpattern ...

  7. 【转】再谈PHP、Python与Ruby

    原文链接:http://www.nowamagic.net/librarys/veda/detail/2504 一句话总结 简单地总结: 假如你想帮他尽快找个活儿,赚到钱,推荐PHP. 假如你想让他成 ...

  8. 业务迁移---web

    #本文是做记录使用,不做为任何参考文档# 迁移代码 将源代码scp至新的server上 搭建服务 yum安装nginx服务 yum install nginx #yum安装 service nginx ...

  9. 软件功能说明书——Thunder团队

    爱阅APP功能说明书 一.引言 相信大家都使用过电子书阅读器,相对于纸质版书籍电子书APP做到了环保.易存储.便携.因此我们Thunder团队开发了——爱阅APP,以下内容是Alpha版的功能说明书. ...

  10. asp.net .net4.0使用异步编程

    "; Action<object> ac = (object obj) => { Debug.WriteLine("睡眠开始:" + DateTime. ...