![](https://img-blog.csdnimg.cn/20201014180756926.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
动态规划
Gipsyu
这个作者很懒,什么都没留下…
展开
-
BZOJ 4300 DP
https://www.lydsy.com/JudgeOnline/problem.php?id=4300一道比较简单的DP题如果按照经典的DP思维肯定要超时这是你如果撕心裂肺的想拿什么去维护的话只能说明你学数据结构学傻了直接记录每一位为1的最大值每次经过一个数字都更新他一发AC代码:#include<bits/stdc++.h>using namespace std;typede...原创 2018-04-17 16:09:23 · 157 阅读 · 0 评论 -
LuoGu 1373 DP
https://www.luogu.org/problemnew/show/P2279最右子结构不是太难找但是这题有点细节要注意第一是压缩状态纬度如果在每个点上都建立二维的数量信息那么总共会四维会爆空间下面就是这道题的精髓了因为我们只关心的是两个人的差值并不关心两个人的所取的数量多少所以可以把二维压缩到一维整体来说就是三维第二是决策点开始的时候只能一个人取这点要注意不错的一道好题Code of A...原创 2018-06-05 17:26:21 · 164 阅读 · 0 评论 -
LuoGu 1439 Lis
https://www.luogu.org/problemnew/show/P1439Just look is the exposed Lcs ProblemBut the range of Data is not allowedBut attention that this is the permutationSo you can choose a permutation as the stan...原创 2018-06-05 17:36:24 · 147 阅读 · 0 评论 -
POJ 1179 Interval DP
https://vjudge.net/problem/POJ-1179You should not only DP the Maxbut also DP the minAnd using the double lengththe time will from the n^4 reduce to the n^3Code of AC:#include<iostream>using nam...原创 2018-05-31 22:33:09 · 164 阅读 · 0 评论 -
BZOJ 3384 Dynamic Programming
https://www.lydsy.com/JudgeOnline/problem.php?id=3384A problem of DPnot too difficultYou should DP the information of the time, the position and the number of stepCode of AC:#include<bits/stdc++.h&...原创 2018-06-01 22:15:02 · 158 阅读 · 0 评论 -
NowCoder 多校第一场E
挺有意思的DP一开始有个大致的思路但是没想到怎么去重AC代码#include<bits/stdc++.h>using namespace std;typedef long long ll;const int N=1e5+10,M=1e9+7;ll A[N],ans[N],DP[N][20];int main(){ int n,m,k; while(~sc...原创 2018-08-29 14:29:42 · 148 阅读 · 0 评论 -
牛客练习赛25 F 堆优化DP
https://www.nowcoder.com/acm/contest/158/F这题太明显了显然的最优子结构然后总是从最小的决策之后就是拿堆来优化一下不就行了这题为什么会是F题比赛上还那么少的人做出来不理解:#include<bits/stdc++.h>using namespace std;const int N=3e5+10;int A[...原创 2018-08-30 10:01:06 · 146 阅读 · 0 评论 -
HihoCoder 1636 区间DP
一个比较有意思的区间DP问题怎么说呢得自己把DP模型建出来怎么设置状态是DP问题的关键代码: #include<bits/stdc++.h>using namespace std;typedef long long ll;ll DP[110][110][110];int A[110];const int inf=1<<30;int m...原创 2018-09-02 11:10:55 · 223 阅读 · 0 评论 -
BZOJ3437 斜率优化
#include<bits/stdc++.h>using namespace std;typedef long long ll;const int N=1e6+10;ll A[N],B[N],F[N],P[N],S[N],DP[N];int main(){ //freopen("1.in","r",stdin); int n; scanf("%d",&n);...原创 2018-12-09 11:38:42 · 125 阅读 · 0 评论 -
解决斜率优化问题的一个玄学奇葩方法
这是一个最坏情况n^2,但本机各种随机数据测试都接近o(n)的时间,HDU,POJ,BZOJ上运行时间也只是该题最短时间的两三倍,而且1e6数据还没开读入挂。但是只是随机数据下接近线性,但是如果故意造数据,随便卡。BZOJ 3437: 时限10sPOJ 1180: 时限1sHDU3507: 时限1s这样写的前提是,x变量随着r单调递增。以后这类题可以前莽一发试试...原创 2018-12-09 12:02:08 · 303 阅读 · 0 评论 -
POJ1180 斜率优化
#include<iostream>using namespace std;typedef long long ll;const int N=1e5+10;ll T[N],F[N],ANS[N],S[N],s;int main(){ int n,s; cin>>n>>s; for(int i=1;i<=n;++i)cin...原创 2018-12-09 11:48:34 · 250 阅读 · 0 评论 -
LuoGu 1005 Interval DP
https://www.luogu.org/problemnew/show/P1005Such good a problem这题很明显区间DP最优子结构也很明显A了之后发现别人写的怪怪的都要算幂其实不用每次区间决策都往上次决策上乘个2简单漂亮这有一点秦九韶算法的思想Code of AC:#include<bits/stdc++.h>using namespace std;const...原创 2018-06-05 17:20:45 · 172 阅读 · 0 评论 -
HDU 6212 Interval DP
https://vjudge.net/problem/HDU-6212和BZOJ上的一道题挺像的但是为什么我HDU上过了BZOJ上没过??(大雾)这题是很有象征意义的因为是我大学入ACM坑里的一个标志九个月前学长他们在打青岛网络赛当时我第一次见到这题卧槽!这么难不过现在我会写了虽然自己只想出了一半吧还是那句话我总是没法判断我想算法的正确性可能是思维还不够吧这题蛮好的一道好题区间DP决策的时候要分情...原创 2018-06-04 20:35:01 · 203 阅读 · 0 评论 -
BZOJ1044 二分+DP
https://www.lydsy.com/JudgeOnline/status.php?user_id=williamking5很不错的一道题第一问二分答案的套路水题第二问DP的思想先用nlogn 二分处理一下这样就不用写单调队列了最后被卡常数了随便的优化一下过了看样子应该是卡的我一两秒左右挺不错的一道题我完全靠我自己做了出来AC代码:#include<bits/stdc++.h>...原创 2018-04-11 21:32:05 · 210 阅读 · 0 评论 -
第八届山东省浪潮杯K题
http://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Index/problemdetail/pid/3903.html官方说这是一个很难的DP然后我随便想了一下切了哈哈哈虽然我ACM水平不强吧但感觉在山东还是能混上一两下的这题的精髓在于你的DP顺序也就是你的排序AC代码:#include<bits/stdc++.h>using nam...原创 2018-04-23 22:14:27 · 159 阅读 · 0 评论 -
UVA10859 树形DP
https://vjudge.net/problem/UVA-10859和我之前做的一道BZOJ有一点像我感觉这道题的灵魂并不在于树形DP而是巧妙地将两个状态用一种表达方式合并成了一种状态因为灯数是主要部分,会起决定作用而尽量要让大街的被一次照亮的次数要少所以取一个大数M将状态表示成为a*M+b不断的DP这个状态就变得简单AC代码:#include<bits/stdc++.h>usi...原创 2018-04-21 10:44:33 · 184 阅读 · 0 评论 -
POJ3666 DP
http://poj.org/problem?id=3666题意比较简单就是问改最少的次数将一个序列变成一个单调序列题解挺神的每个数不会再改成除这个序列之外的数如果能理解这个那么对这个序列排下序然后枚举每个位置的数可以在n^2的复杂度内完成计算很有意思剩下的就是比较点单的DP了AC代码:#include<iostream>#include<algorithm>#incl...原创 2018-05-03 19:29:50 · 141 阅读 · 0 评论 -
BZOJ5281 分数规划+DP
https://www.lydsy.com/JudgeOnline/problem.php?id=5281第一次写分数规划的题挺神奇的这道题就是分数规划但是还有一个W的限制所以每次判断加上一个DP类似于01背包AC代码:#include<bits/stdc++.h>using namespace std;typedef long long ll;const ll N=300;l...原创 2018-04-27 16:07:45 · 269 阅读 · 0 评论 -
BZOJ 1613 DP
https://www.lydsy.com/JudgeOnline/problem.php?id=1613One Y! beautiful Z ZA easy problem by DPyou should record the time and fatigue and the statusand DP one by one is just OK!code of AC:#include<bi...原创 2018-05-19 08:39:18 · 221 阅读 · 0 评论 -
Codeforce 559C DP
The Dynamic Programming is extensive and profound!This problem you should think from the black cellsCode of AC:#include<bits/stdc++.h>#define x first#define y secondusing namespace std;typed...原创 2018-05-21 14:31:05 · 148 阅读 · 0 评论 -
NowCoder HNNU L
https://www.nowcoder.com/acm/contest/127/LA problem of Interval DP这题我是一血哦这题其实我的思路也不是太清晰想了一个二维DP但是区间决策的时候瞎搞了搞然后wa了几次之后结合了一下过了我看别人写的都是三维DP窃窃自喜但是可能是我幸运吧让我二维DP过了我这么DP对不对我也不知道==DP这个东西有时候我没法判断自己想的是否正确不过能写出一...原创 2018-06-02 22:32:31 · 155 阅读 · 0 评论 -
HDU 4539 DP
https://vjudge.net/problem/HDU-4539一道不太容易的状压DP之前必须要处理一下单纯的DP二进制会爆好久没押行写了(请不要理会一个押行选手Code of AC:#include<bits/stdc++.h>using namespace std;bool check(int x,int y){return ((x<<1)&y)==0...原创 2018-06-04 20:28:42 · 129 阅读 · 0 评论 -
FZU2129 DP本质不同的子序列
#include<iostream>#include<stdio.h>#include<string.h>using namespace std;typedef long long ll;const ll N=1e6+10,M=1e9+7;ll A[N],B[N],DP[N];int main(){ int n; while(ci...原创 2019-02-20 22:42:28 · 1283 阅读 · 0 评论