后缀自动机看不懂啊QAQ

放弃了还是看点更有用的东西吧,比如斜率优化DP

先水一道

#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 1000003
#define read(x) x=getint()
using namespace std;
typedef long long LL;
inline LL getint() {
LL k = 0; int fh = 1; char c = getchar();
for(; c < '0' || c > '9'; c = getchar())
if (c == '-') fh = -1;
for(; c >= '0' && c <= '9'; c = getchar())
k = k * 10 + c - '0';
return k * fh;
}
LL x[N], p[N], c[N], sum[N], b[N], f[N], n, q[N];
inline LL fz(int x, int y) {
return f[x] + b[x] - f[y] - b[y];
}
inline LL fm(int x, int y) {
return sum[x] - sum[y];
}
int main() {
read(n);
for(int i = 1; i <= n; ++i)
read(x[i]), read(p[i]), read(c[i]);
for(int i = 1; i <= n; ++i)
sum[i] = sum[i - 1] + p[i], b[i] = b[i - 1] + p[i] * x[i];
int h = 0, t = 1, now;
for(int i = 1; i <= n; ++i) {
while (h < t - 1 && fz(q[h + 1], q[h]) < x[i] * fm(q[h + 1], q[h]))
++h;
now = q[h];
f[i] = f[now] + (sum[i] - sum[now]) * x[i] - b[i] + b[now] + c[i];
while (h < t - 1 && fz(q[t - 1], q[t - 2]) * fm(i, q[t - 1]) > fz(i, q[t - 1]) * fm(q[t - 1], q[t - 2]))
--t;
q[t++] = i;
}
printf("%lld\n", f[n]);
return 0;
}

我好蒟蒻啊,省选要爆零!

【BZOJ 1096】【ZJOI 2007】仓库建设 DP+斜率优化的更多相关文章

  1. 【BZOJ 1096】 [ZJOI2007]仓库建设 (斜率优化)

    1096: [ZJOI2007]仓库建设 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 3940  Solved: 1736 Description ...

  2. BZOJ 1096: [ZJOI2007]仓库建设( dp + 斜率优化 )

    dp(v) = min(dp(p)+cost(p,v))+C(v) 设sum(v) = ∑pi(1≤i≤v), cnt(v) = ∑pi*xi(1≤i≤v), 则cost(p,v) = x(v)*(s ...

  3. BZOJ1096: [ZJOI2007]仓库建设(dp+斜率优化)

    Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 5790  Solved: 2597[Submit][Status][Discuss] Descript ...

  4. 【BZOJ1096】【ZJOI2007】仓库建设(斜率优化,动态规划)

    [BZOJ1096][ZJOI2007]仓库建设(斜率优化,动态规划) 题面 Description L公司有N个工厂,由高到底分布在一座山上.如图所示,工厂1在山顶,工厂N在山脚.由于这座山处于高原 ...

  5. BZOJ 1096: [ZJOI2007]仓库建设(DP+斜率优化)

    [ZJOI2007]仓库建设 Description L公司有N个工厂,由高到底分布在一座山上.如图所示,工厂1在山顶,工厂N在山脚.由于这座山处于高原内陆地区(干燥少雨),L公司一般把产品直接堆放在 ...

  6. BZOJ 1096 [ZJOI2007]仓库建设(斜率优化DP)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1096 [题目大意] 有个斜坡,有n个仓库,每个仓库里面都有一些物品,物品数目为p,仓库 ...

  7. BZOJ 1096 [ZJOI2007]仓库建设:斜率优化dp

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1096 题意: 有n个工厂,从左往右排成一排,分别编号1到n. 每个工厂里有p[i]件产品, ...

  8. bzoj 1096: [ZJOI2007]仓库建设【斜率优化】

    好眼熟啊 直接dp显然很难算,所以设val为只在n点建一个仓库的费用,然后设f[i]为在i~n点建若干仓库并且i点一定建一个仓库的最大省钱数 转移很显然,设s为p的前缀和,f[i]=max{f[j]+ ...

  9. BZOJ1096 ZJOI2007 仓库建设 【斜率优化DP】

    BZOJ1096 ZJOI2007 仓库建设 Description L公司有N个工厂,由高到底分布在一座山上.如图所示,工厂1在山顶,工厂N在山脚.由于这座山处于高原内陆地区(干燥少雨),L公司一般 ...

随机推荐

  1. 以纯面向对象的JS编写最基本的数据字典案例

    之前有讲到过数据字典,什么是数据字典,用来干啥的,这个不细说了,今天来说说如何实现数据字典功能 无非就是维护数据字典,对数据字典对象进行增删改成,曾经我写过一个页面跳转形式的,十分简单,不说了,今天用 ...

  2. UNITY3D的变量初始化问题

    大部分是代码声明变量,而变量的初始化值在编辑器中指定,不在代码中直接指定 奇怪! 而且只有Public的才能在编辑器中出现,如果你改为Private就不再显示,如果你再改回PUBLIC,原先指定的初化 ...

  3. java 25 - 1 网络编程的概述

    网络编程概述 计算机网络 是指将地理位置不同的具有独立功能的多台计算机及其外部设备,通过通信线路连接起来,在网络操作系统,网络管理软件及网络通信协议的管理和协调下,实现资源共享和信息传递的计算机系统. ...

  4. gzip: stdout: No space left on device问题的解决

    一.问题描述 最近安装了ubuntu14.04,并在ubuntu14.04中编译了一次内核.这之后大部分情况下用sudo apt-get install 安装应用都会出现“gzip: stdout: ...

  5. css3和原生js时钟

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. Func<T,TResult>泛型委托

    描述: 封装一个具有一个参数并返回TResult参数指定的类型值的方法. 语法: public delegate TResult Func<T,TResult>(T arg); 参数类型: ...

  7. js profiler

    https://developers.google.com/web/fundamentals/performance/critical-rendering-path/?hl=en https://de ...

  8. iOS APNS配置(转)

    Introduction To send Push notification to an application/device couple you need an unique device tok ...

  9. Lowest Common Ancestor of a Binary Tree

    Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According ...

  10. TopCoder

    在TopCoder下载好luncher,网址:https://www.topcoder.com/community/competitive%20programming/ 选择launch web ar ...