和上题类似吧。。。。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 1000050
using namespace std;
long long n,x[maxn],p[maxn],c[maxn],sum1[maxn],sum2[maxn],f[maxn],q[maxn],l,r,g[maxn];
long long read()
{
char ch;long long data=;
while (ch<'' || ch>'') ch=getchar();
while (ch>='' && ch<='')
{
data=data*+ch-'';
ch=getchar();
}
return data;
}
double k(long long a,long long b)
{
return (double)(g[a]-g[b])/(x[a]-x[b]);
}
void dp()
{
l=r=;q[l]=;g[]=c[];f[]=c[];
for (long long i=;i<=n;i++)
{
g[i]=f[i-]+c[i]-sum1[i]+sum2[i]*x[i];
while ((r-l) && (k(q[r-],q[r])>k(q[r],i))) r--;
q[++r]=i;
while ((r-l) && (k(q[l],q[l+])<=sum2[i])) l++;
f[i]=f[q[l]-]+c[q[l]]+sum1[i]-sum1[q[l]]-(sum2[i]-sum2[q[l]])*x[q[l]];
}
}
int main()
{
n=read();
for (register long long i=;i<=n;i++) x[i]=read(),p[i]=read(),c[i]=read();
for (register long long i=;i<=n;i++) x[i]=x[n]-x[i];
for (register long long i=;i<=n/;i++) swap(p[i],p[n-i+]),swap(c[i],c[n-i+]),swap(x[i],x[n-i+]);
for (register long long i=;i<=n;i++)
{
sum1[i]=sum1[i-]+p[i]*x[i];
sum2[i]=sum2[i-]+p[i];
}
dp();
printf("%lld\n",f[n]);
return ;
}

BZOJ 1096 仓库建设的更多相关文章

  1. bzoj 1096 仓库建设 -斜率优化

    L公司有N个工厂,由高到底分布在一座山上.如图所示,工厂1在山顶,工厂N在山脚.由于这座山处于高原内陆地区(干燥少雨),L公司一般把产品直接堆放在露天,以节省费用.突然有一天,L公司的总裁L先生接到气 ...

  2. bzoj 1096 仓库建设 —— 斜率优化DP

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1096 设 f[i] 为 i 作为最后一个仓库时前 i 个工厂的答案,最后的答案当然是 f[n ...

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

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

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

    http://www.lydsy.com/JudgeOnline/problem.php?id=1096 首先得到dp方程(我竟然自己都每推出了QAQ)$$d[i]=min\{d[j]+cost(j+ ...

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

    1096: [ZJOI2007]仓库建设 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 4201  Solved: 1851[Submit][Stat ...

  6. BZOJ 1096 【ZJOI2007】 仓库建设

    Description L公司有N个工厂,由高到底分布在一座山上.如图所示,工厂1在山顶,工厂N在山脚.由于这座山处于高原内陆地区(干燥少雨),L公司一般把产品直接堆放在露天,以节省费用.突然有一天, ...

  7. bzoj 1096: [ZJOI2007]仓库建设 斜率優化

    1096: [ZJOI2007]仓库建设 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2242  Solved: 925[Submit][Statu ...

  8. bzoj 1096 [ZJOI2007]仓库建设(关于斜率优化问题的总结)

    1096: [ZJOI2007]仓库建设 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 3234  Solved: 1388[Submit][Stat ...

  9. 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 ...

随机推荐

  1. 常用备份工具是mysql自带的mysqldump

    常用备份工具是mysql自带的mysqldump,mysqldump -u root -p密码 dbname >d:\test.sql ------------备份某个库mysqldump -u ...

  2. php时间设置为本地

    PHP Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to ...

  3. Codeforces Round #372 (Div. 2) C. Plus and Square Root

    题目链接 分析:这题都过了2000了,应该很简单..写这篇只是为了凑篇数= = 假设在第级的时候开方过后的数为,是第级的系数.那么 - 显然,最小的情况应该就是, 化简一下公式,在的情况下应该是,注意 ...

  4. HEAD FIRST HTML & CSS学习笔记

    CSS部分 1. border-bottom属性控制元素下边框的外观.   eg: border-bottom:1px solid maroon;  P265 下划线 text-decoration: ...

  5. jquery multiselect使用示例

    多选下拉框开源组件:https://github.com/ehynds/jquery-ui-multiselect-widget html部分: <select multiple id=&quo ...

  6. 爹地,我找到了!15个极好的Linux find命令示例

    爹地,我找到了!15个极好的Linux find命令示例 http://blog.jobbole.com/48931/ 妈咪,我找到了!15个实用的Linux find命令示例 http://blog ...

  7. 怎么把Windows主机上的目录共享到Ubuntu上

    使用Oracle VM VirtualBox在Windows主机上创建了一台Ubuntu虚拟机,怎么把宿主机上的目录共享到Ubuntu上,可使用以下方法: eg.把Windows主机上D盘里的test ...

  8. Git & GitHub

    使用 Git 和 GitHub 有一段时间了,总结下经验. 起初接触 Git 是先遇到 GitHub 的,当时傻傻分不清这两者的区别,毕竟名字都那么像,刚开始只想用酷酷的方法 clone 代码(SSH ...

  9. 几个实用的mysql函数

    在工作中,处理数据时候往往使用php要废很多脑筋和写很多东西,如果不考虑代码的阅读性试试几个mysql的函数可以解决许多常见需求: 1.截取字符串函数: left() 从左开始截取字符串  right ...

  10. OC NSString 基本操作(用到补充持续更新)

    1.将字符串拆分成数组 NSString *string = @"1,2,3,4"; NSArray *array = [string componentsSeparatedByS ...