Print Article HDU - 3507 -斜率优化DP】的更多相关文章

思路 : 1,用一个单调队列来维护解集. 2,假设队列中从头到尾已经有元素a b c.那么当d要入队的时候,我们维护队列的下凸性质, 即如果g[d,c]<g[c,b],那么就将c点删除.直到找到g[d,x]>=g[x,y]为止,并将d点加入在该位置中. 3,求解时候,从队头开始,如果已有元素a b c,当i点要求解时,如果g[b,a]<sum[i], 那么说明b点比a点更优,a点可以排除,于是a出队.最后dp[i]=getDp(q[head]). #include<bits/std…
Print Article Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total Submission(s): 11141    Accepted Submission(s): 3393 Problem Description Zero has an old printer that doesn't work well sometimes. As it is antiqu…
Print Article Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total Submission(s): 12185    Accepted Submission(s): 3733 Problem Description Zero has an old printer that doesn't work well sometimes. As it is antiqu…
在kuangbin巨巨博客上学的. #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; + ; int d[maxn], Q[maxn], sum[maxn]; int head, tail; int n, M; int inline dx(int i, int j) { return sum[j] - sum[i…
A - Print Article HDU - 3507 今天刚刚学习了一下斜率dp,感觉还ok,主要就是要推这个斜率,然后利用数据结构来优化. 推荐两篇写的比较好的博客,https://www.cnblogs.com/orzzz/p/7885971.html ----> 这个主要学习这个斜率dp的思路 https://www.cnblogs.com/ka200812/archive/2012/08/03/2621345.html ---> 这个主要看代码,中间过程感觉有点问题. https:…
Print Article Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total Submission(s): 4990    Accepted Submission(s): 1509 Problem Description Zero has an old printer that doesn't work well sometimes. As it is antique…
我的第一道斜率优化. 就这道题而言,写出原始的方程: dp[i] = min{ dp[j] + (sum[i]-sum[j])2  + M | j in [0,i) } O(n^2)的复杂度肯定超时,要么优化转移,要么重写方程. 斜率优化的思想就是减少不必要的枚举(即不枚举肯定不会成为决策点的j). 我们考虑两个位置p<q<i “选择q比选择p优” 当且仅当 dp[q]+(sum[i]-sum[q])2+M < dp[p]+(sum[i]-sum[p])2+M 化简右边即: [ (dp[…
Cross the Wall Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 327680/327680 K (Java/Others)Total Submission(s): 4479    Accepted Submission(s): 812 Problem Description “Across the Great Wall, we can reach every corner in the world!” Now the…
Covered Walkway Time Limit: 30000/10000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 1496    Accepted Submission(s): 602 Problem Description Your university wants to build a new walkway, and they want at least p…
题意:n个数之间放m个障碍,分隔成m+1段.对于每段两两数相乘再求和,然后把这m+1个值加起来,让这个值最小. 设: d(i, j)表示前i个数之间放j个炸弹能得到的最小值 sum(i)为前缀和,cost(i)为前i个数两两相乘之和. 则有状态转移方程: 设0 ≤ l < k < i,且k比l更优,有不等式: 整理得到,注意不等号方向: 最后变成了斜率的形式,下面就用一个队列维护即可. #include <iostream> #include <cstdio> #inc…