题目链接:http://codeforces.com/problemset/problem/1029/B 题目大意:从数组a中选出一些数组成数组b,要求 b[i+1]<=b[i]*2 . 一开始想到的是O(n^2)的动态规划,但是超时了,下面是超时的代码. #include <iostream> using namespace std; const int maxn = 200020; int n, a[maxn], f[maxn], res = 0; int main() { cin…
B. Creating the Contest time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given a problemset consisting of nn problems. The difficulty of the ii-th problem is aiai. It is guaranteed t…
B. Psychos in a Line Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem/319/B Description There are n psychos standing in a line. Each psycho is assigned a unique integer from 1 to n. At each step every psycho who h…
http://codeforces.com/contest/1029/problem/B You are given a problemset consisting of nn problems. The difficulty of the ii-th problem is aiai. It is guaranteed that all difficulties are distinct and are given in the increasing order. You have to ass…
洛谷题目传送门 闲话 看完洛谷larryzhong巨佬的题解,蒟蒻一脸懵逼 如果哪年NOI(放心我这样的蒟蒻是去不了的)又来个决策单调性优化DP,那蒟蒻是不是会看都看不出来直接爆\(0\)?! 还是要想点办法,不失一般性也能快捷地判定决策单调. 对于判定决策单调的分析 再补一句决策单调性的概念:状态转移方程形如\(f_i=\min/\max_{j=1}^{i-1} g_j+w_{i,j}\),且记\(f_i\)的最优决策点为\(p_i\)(也就是\(f_i\)从\(g_{p_i}+w_{i,p_…
洛谷题目传送门 安利蒟蒻斜率优化总结 由于人是每次都是连续一段一段地选,所以考虑直接对\(x\)记前缀和,设现在的\(x_i=\)原来的\(\sum\limits_{j=1}^ix_i\). 设\(f_i\)为安排前\(i\)个人的最大值\((f_0=0)\) \(f_i=\max\limits_{j=0}^{i-1}\{f_j+a(x_i-x_j)^2+b(x_i-x_j)+c\}\) \(\quad=\max\limits_{j=0}^{i-1}\{f_j-2ax_ix_j+ax_j^2-b…
洛谷题目传送门 疯狂%%%几个月前就秒了此题的Tyher巨佬 借着这题总结一下决策单调性优化DP吧.蒟蒻觉得用数形结合的思想能够轻松地理解它. 首先,题目要我们求所有的\(p_i\),那么把式子变一下 \[p_i\ge a_j-a_i+\sqrt{|i-j|}\] \[p_i=\max\limits_{j=1}^n\{a_j+\sqrt{|i-j|}\}-a_i\] 绝对值看着很不爽,我们把它拆开 \[p_i=\max(\max_{j=1}^i\{a_j+\sqrt{i-j}\},\max_{j…
D. Psychos in a Line time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output There are n psychos standing in a line. Each psycho is assigned a unique integer from 1 to n. At each step every psycho…
B - Strip 思路:简单dp,用st表+单调队列维护一下. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PII pair<int, int> #define y1 skldjfskldjg #define y2 skldfjsklejg using namespace std; ; ; const int…
前言 单调队列优化\(DP\)应该还算是比较简单容易理解的吧,像它的升级版斜率优化\(DP\)就显得复杂了许多. 基本式子 单调队列优化\(DP\)的一般式子其实也非常简单: \[f_i=max_{j=max(i-t,1)}^{i-1}(s(i)+g(j))\] 其中\(t\)是一个常数,\(s(i)\)是一个只与\(i\)有关的函数,\(g(j)\)是一个只与\(j\)有关的函数,式子中的\(max\)其实也可以替换成\(min\),但这里以\(max\)为例. 由于\(s(i)\)只与\(i…