留坑

为什么别人家的斜率优化跟我一点都不一样!

为什么斜率都要变成正的。。。

为什么要那么推式子

为什么不能直接做啊。。。。。

为什么不把0去掉去秒WA啊

为什么叉积去了0也过不了啊

woc啊

 #include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iostream> using namespace std; void setIO(const string& s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
template<typename Q> Q read(Q& x) {
static char c, f;
for(f = ; c = getchar(), !isdigit(c); ) if(c == '-') f = ;
for(x = ; isdigit(c); c = getchar()) x = x * + c - '';
if(f) x = -x;
return x;
}
template<typename Q> Q read() {
static Q x; read(x); return x;
} typedef long long LL;
const int N = + ; LL sqr(const LL& x) {
return x * x;
} LL f[N], g[N], sum[N];
int q[N]; LL up(int i) {
return g[i] - sqr(sum[i]);
} LL up(int i, int j) {
return up(j) - up(i);
} LL down(int i, int j) { // >= 0
return sum[j] - sum[i];
} double slope(int i, int j) {
return up(i, j) / (double) down(i, j);
}
int n; struct Node {
LL x, y;
Node() {}
Node(const LL& x, const LL& y) : x(x), y(y) {}
Node operator - (const Node& rhs) const {
return Node(x - rhs.x, y - rhs.y);
}
}p[N]; LL Cross(const Node& a, const Node& b) {
return a.x * b.y - b.x * a.y;
} void dp(int st) {
int L = , R = ;
q[R++] = st;
for(int i = st + ; i <= n; i++) {
// while(L + 1 < R && -sum[i] < slope(q[L], q[L + 1])) L++;
// while(L + 1 < R && -sum[i] * down(q[L], q[L + 1]) < up(q[L], q[L + 1])) L++;
while(L + < R && Cross(Node(, -sum[i]), p[L + ] - p[L]) >= ) L++;
int j = q[L];
f[i] = g[j] + sum[j] * (sum[i] - sum[j]);
// while(L + 1 < R && slope(q[R - 2], q[R - 1]) < slope(q[R - 2], i)) R--;
// while(L + 1 < R && up(q[R - 2], q[R - 1]) * down(q[R - 2], i) < up(q[R - 2], i) * down(q[R - 2], q[R - 1])) R--;
Node u(sum[i], up(i));
while(L + < R && Cross(p[R - ] - p[R - ], u - p[R - ]) >= ) R--;
q[R] = i, p[R++] = u;
}
for(int i = st + ; i <= n; i++) g[i] = f[i];
} int main() {
#ifdef DEBUG
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif read(n);
int k = read<int>(); for(int i = ; i <= n; i++) {
int x = read<int>();
if(!x) i--, n--;
else sum[i] = sum[i-] + x;
// sum[i] = sum[i-1] + read<int>();
} for(int i = ; i <= k; i++) dp(i); printf("%lld\n", g[n]); return ;
}

bzoj3675: [Apio2014]序列分割的更多相关文章

  1. bzoj3675[Apio2014]序列分割 斜率优化dp

    3675: [Apio2014]序列分割 Time Limit: 40 Sec  Memory Limit: 128 MBSubmit: 3508  Solved: 1402[Submit][Stat ...

  2. BZOJ3675 [Apio2014]序列分割 【斜率优化dp】

    3675: [Apio2014]序列分割 Time Limit: 40 Sec  Memory Limit: 128 MB Submit: 3366  Solved: 1355 [Submit][St ...

  3. [Bzoj3675][Apio2014]序列分割(斜率优化)

    3675: [Apio2014]序列分割 Time Limit: 40 Sec  Memory Limit: 128 MBSubmit: 4021  Solved: 1569[Submit][Stat ...

  4. BZOJ3675 [Apio2014]序列分割 动态规划 斜率优化

    原文链接http://www.cnblogs.com/zhouzhendong/p/8697258.html 题目传送门 - BZOJ3675 题意 对于一个非负整数序列,小H需要重复k次以下的步骤: ...

  5. BZOJ3675 Apio2014 序列分割 【斜率优化】

    Description 小H最近迷上了一个分隔序列的游戏.在这个游戏里,小H需要将一个长度为n的非负整数序列分割成k+1个非空的子序列.为了得到k+1个子序列,小H需要重复k次以下的步骤: 1.小H首 ...

  6. BZOJ3675: [Apio2014]序列分割(斜率优化)

    Time Limit: 40 Sec  Memory Limit: 128 MBSubmit: 4186  Solved: 1629[Submit][Status][Discuss] Descript ...

  7. 2018.09.29 bzoj3675: [Apio2014]序列分割(斜率优化dp)

    传送门 斜率优化dp经典题目. 首先需要证明只要选择的K个断点是相同的,那么得到的答案也是相同的. 根据分治的思想,我们只需要证明有两个断点时成立,就能推出K个断点时成立. 我们设两个断点分成的三段连 ...

  8. [luogu3648][bzoj3675][APIO2014]序列分割【动态规划+斜率优化】

    题目大意 让你把一个数列分成k+1个部分,使分成乘积分成各个段乘积和最大. 分析 首先肯定是无法开下n \(\times\) n的数组,那么来一个小技巧:因为我们知道k的状态肯定是从k-1的状态转移过 ...

  9. 【BZOJ-3675】序列分割 DP + 斜率优化

    3675: [Apio2014]序列分割 Time Limit: 40 Sec  Memory Limit: 128 MBSubmit: 1420  Solved: 583[Submit][Statu ...

随机推荐

  1. 171. Excel Sheet Column Number(C++)

    171. Excel Sheet Column Number Related to question Excel Sheet Column Title Given a column title as ...

  2. UVA10142/PC110108Australian Voting

    UVA10142/PC110108Australian Voting 10142 Australian Voting Accepted C++11 0.769 2014-02-11 05:01:20 ...

  3. 2D动态光照

    对场景内所有点发出射线, 如果射线被某条边阻挡, 则射线停留在阻挡的边上, 如果射线顺利抵达终点, 则对射线偏移-0.001, +0.001角度, 再射出2条射线, 停留在后续的阻挡边上. 把最终的射 ...

  4. 『重构--改善既有代码的设计』读书笔记----Replace Array with Object

    如果你有一个数组,其中的元素各自代表不同东西,比如你有一个 QList<QString> strList; 其中strList[0]代表选手姓名,strList[1]代表选手家庭住址,很显 ...

  5. CSS3圆角(border-radius)

    CSS3中的border-radius支持IE9+,chrome,firefox 2.3+,以及safari3.2+浏览器. border-radius可直接使用,无需加前缀(注意:firefox13 ...

  6. [Python笔记]第十六篇:web框架之Tornado

    Tornado是一个基于python的web框架,xxxxx 安装 python -m pip install tornado 第一个Tornado程序 安装完毕我们就可以新建一个app.py文件,放 ...

  7. [python]获取字符串类型

    >>>type(value) <class 'type'> >>>isinstance(value,type) True/False

  8. Objective-C property属性解析

    @interface … @property (原子性,可写性,内存管理) id name; @end 原子性:    nonatomic, atomic   默认atomic 可写性:    rea ...

  9. 超实用,你get了吗?再也不怕本地文件更新到环境用Linux命令重启服务器了。。。

    来公司这么久,写过不少代码,可是一碰见关于Linux命令操作的马上绕过,每次都是嚷嚷同事过来帮我替换文件,重启服务器,一直害怕接触命令的我一次一次不嫌麻烦,哈哈.有没有醉了?其实我一直都知道操作不难, ...

  10. LightOj_1104 Birthday Paradox

    题目链接 题意: 若一年有n天, 问至少需要多少个人才能满足其中两个人生日相同的概率大于等于0.5? 思路: 经典问题:生日悖论 换成其互斥事件:m个人, 每个人生日都不相同的概率 ≤ 0.5 时最小 ...