![](https://img-blog.csdnimg.cn/20201014180756919.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
动态规划之优化DP
等我学会后缀自动机
侠影之谜
展开
-
CodeForces 315E Sereja and Subsequences (权值线段树+DP)
#include<bits/stdc++.h>using namespace std;#define debug puts("YES");#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)#define ll long long#define lrt int l,int r,int rt#define lson l,m...原创 2020-04-25 22:46:27 · 115 阅读 · 0 评论 -
CodeForces 320D Psychos in a Line (单调栈+DP)
#include<bits/stdc++.h>using namespace std;#define debug puts("YES");#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)#define ll long long#define lrt int l,int r,int rt#define lson l,m...原创 2020-04-21 10:40:29 · 153 阅读 · 0 评论 -
CodeForces 373E Watching Fireworks is Fun (DP+单调队列优化)
#include<bits/stdc++.h>using namespace std;#define debug puts("YES");#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)#define ll long long#define lrt int l,int r,int rt#define lson l,m...原创 2020-04-05 21:26:05 · 163 阅读 · 0 评论 -
HDU 5807 Keep In Touch 优化DP思维+倒序
#include<bits/stdc++.h>using namespace std;#define debug puts("YES");#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)#define per(x,y,z) for(int (x)=(y);(x)>=(z);(x)--)#define ll lon...原创 2020-02-09 23:53:54 · 145 阅读 · 0 评论 -
Educational Codeforces Round 61 (Rated for Div. 2) E. Knapsack(思维优化背包)好题
题目链接:http://codeforces.com/contest/1132/problem/E题目大意给定八种物品每种物品价值为i,(1~8),然后给定一个w,问能达到的不大于w的值最大值是多少。w和物品个数都非常大。题目分析比较神仙的一道背包题目吧算是,我是看了题解才有想法的。对于1到8,其单独取都可以凑成840(取八个数最小公倍数)就是说假定答案是cnt1...原创 2019-03-28 06:57:38 · 187 阅读 · 0 评论 -
CodeForces 960F Pathwalks (主席树结构+动态开点思想+DP)
题目链接:http://codeforces.com/problemset/problem/960/F题目大意给定m个三元组(x,y,z),要求找出符合条件的最大长度序列,其序列要求是:相邻两个,xi=yj&&zi>zj&&j<i.题目分析对于这种转移条件的要求,很明显就是个Dp,然后考虑用啥数据结构维护下就行了,之前遇到...原创 2019-03-22 19:14:28 · 202 阅读 · 0 评论 -
CodeForces 717D Dexterina’s Lab (矩阵快速幂+博弈)
题目链接:http://codeforces.com/problemset/problem/717/D题目大意:给定堆数和每堆石子的最大个数,现在每堆都给定P(X),问其随机玩后先手胜利的概率是多少。题目分析:明显的矩阵快速幂。要注意的坑是我刚开始取上界直接取k<<1了,这样其实有漏洞因为位运算的原因会越界,正解应该是观察位的性质后取最小的二次幂,这里我...原创 2019-02-19 17:33:38 · 256 阅读 · 0 评论 -
Codeforces Round #537 (Div. 2) E. Tree(DP+树状数组统计+LCA)*
题目链接:http://codeforces.com/contest/1111/problem/E题目大意:给定一棵树,和若干个询问,k,m,r和k个数,问把这k个点分成至多m组且每组中的点集没有父节点与子节点的关系,其方案数有多少种。题目分析: 这道题我是看了别人的思路才懂的,果然还是自己太弱了呀。。。先简化问题,如果根是固定的如何考虑,那么观察到m的数据范围去...原创 2019-02-24 18:28:58 · 157 阅读 · 0 评论 -
CodeForces 621E Wet Shark and Blocks (矩阵快速幂+水题)
题目链接:http://codeforces.com/problemset/problem/621/E题目大意:给定b个带有n个数的砖块,每个砖块可以选则一个数字作为要拼凑的数字的下一位,问有多少种选择方案可以使得凑出的数modx等于k.题目分析: 比较裸的矩阵快速幂。我们不难发现矩阵的维度就是x 的限度,100*100的矩阵条件是允许的。然后对b进行幂次级别运算(...原创 2019-02-18 23:17:14 · 195 阅读 · 0 评论 -
Gym 101061G Repeat it (矩阵快速幂+Dp递推式子)
题目链接:http://codeforces.com/gym/101061/problem/G题目大意给定m和n,要求m个n数字形式拼接起来其表示的数模1e9+7题目分析矩阵快速幂水题,递推式子很好列,用二维矩阵快速幂优化下即可.见代码#include<bits/stdc++.h>using namespace std;#define debu...原创 2019-04-10 19:28:22 · 133 阅读 · 0 评论 -
HDU 4734 F(x) (数位DP+优化技巧)*
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4734题目大意给定函数f的定义,问在f函数的定义下,在0到B中有多少个数满足,小于等于f(A)的关系并且A事先给定。题目分析数位DP处理,但是注意到这题时限非常小,朴素想法是dp[pos][sum],这样会超时,然后考虑加一维度存储特定的f(A)但值会很大数组开不下,看...原创 2019-03-29 06:40:55 · 175 阅读 · 0 评论 -
CodeForces 977F Consecutive Subsequence (贪心+DP)
题目链接:http://codeforces.com/problemset/problem/977/F贪心性质+DP#include<bits/stdc++.h>using namespace std;#define debug puts("YES");#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)#de...原创 2019-04-26 17:18:56 · 128 阅读 · 0 评论 -
HDU6495 冰水挑战(DP+转换思维)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6495题目分析既然无法暴力记录第i轮时候j体力可以抗多少回合,那么就把数值大的放入数组内容中,即dp(i,j)代表前i轮中,抗住j轮的留下的最大体力这样转换后思路就清晰多了,方程不难,甚至空间也可以压缩.#include<bits/stdc++.h>u...原创 2019-04-27 22:22:30 · 133 阅读 · 0 评论 -
CodeForces 479E Riding in a Lift (优化DP,打标记+前缀和)
主要是往下更新下一层DP的时候要用到前缀和的思想打标记.#include<bits/stdc++.h>using namespace std;#define debug puts("YES");#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)#define ll long long#define lrt i...原创 2019-05-05 12:57:00 · 152 阅读 · 0 评论 -
CodeForces 478D Red-Green Towers (DP+优化状态)
很容易想到二维DP暴力吧,但是题目不允许,于是开二维dp(i,j)表示堆到i层且r用了j个的方案数,如果i*(i+1)/2<=g+j,dp(i,j)+=dp(i-1,j);表示这层如果不放r的话如果j大于等于i,dp(i,j)+=dp(i-1,j-i);那么压缩下空间应该不难,初始化dp(0)=1#include<bits/stdc++.h>using...原创 2019-05-15 17:08:39 · 174 阅读 · 0 评论 -
CodeForces 264C Choosing Balls (DP+优化维护)
题目链接:http://codeforces.com/problemset/problem/264/C#include<bits/stdc++.h>using namespace std;#define debug puts("YES");#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)#define ll lo...原创 2019-06-13 20:46:52 · 186 阅读 · 0 评论 -
Codeforces Round #536 (Div. 2) E. Lunar New Year and Red Envelopes(DP+muitiset优化)
题目链接:http://codeforces.com/contest/1106/problem/E#include<bits/stdc++.h>using namespace std;#define debug puts("YES");#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)#define ll long ...原创 2019-02-03 20:24:20 · 143 阅读 · 0 评论 -
Gym 100712L Alternating Strings II (线段树+DP)
题目链接:http://codeforces.com/gym/100712/attachments#include<bits/stdc++.h>using namespace std;#define debug puts("YES");#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)#define ll long ...原创 2019-01-23 08:06:15 · 125 阅读 · 0 评论 -
Gym 100827F Knights (状压DP+矩阵快速幂)
题目链接:http://codeforces.com/gym/100827/attachments#include<bits/stdc++.h>using namespace std;#define debug puts("YES");#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)#define ll long l...原创 2019-02-02 16:26:47 · 184 阅读 · 0 评论 -
Codeforces 597D Subsequences (二维树状数组入门+DP优化) 高清重制版
For the given sequence with n different elements find the number of increasing subsequences with k + 1 elements. It is guaranteed that the answer is not greater than 8·1018.InputFirst line contain...原创 2018-08-31 14:50:09 · 366 阅读 · 0 评论 -
Codeforces 834D The Bakery (线段树+DP+单调性质)*
题目链接:https://cn.vjudge.net/problem/CodeForces-834D#include<bits/stdc++.h>#pragma comment(linker,"/STACK:1024000000,1024000000")using namespace std;#define debug puts("YES");#define rep(x...原创 2018-09-08 09:21:27 · 141 阅读 · 0 评论 -
HDU 5406 CRB and Apple (DP+树状数组)思维好题*
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5406#include<bits/stdc++.h>#pragma comment(linker,"/STACK:1024000000,1024000000")using namespace std;#define debug puts("YES");#define rep(...原创 2018-09-14 06:11:26 · 168 阅读 · 0 评论 -
51Nod - 1376 最长递增子序列的数量(树状数组+DP)*
题目链接:https://cn.vjudge.net/problem/51Nod-1376#include<bits/stdc++.h>using namespace std;#define debug puts("YES");#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)#define read(x,y) sca...原创 2018-09-19 17:47:32 · 342 阅读 · 0 评论 -
Codeforces 834D The Bakery (线段树+DP)
题目链接:http://codeforces.com/problemset/problem/834/D#include<bits/stdc++.h>using namespace std;#define debug puts("YES");#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)#define read(x...原创 2018-09-29 11:40:07 · 197 阅读 · 0 评论 -
uva 10280 Old Wine Into New Bottles(完全背包+剪枝)*
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1221#include<bits/stdc++.h>using namespace std;#define debug puts("YES");#...原创 2018-09-29 15:13:03 · 184 阅读 · 0 评论 -
Codeforces 474E Pillars (线段树+DP+二分+离散)
题目链接:http://codeforces.com/problemset/problem/474/E#include<bits/stdc++.h>using namespace std;#define debug puts("YES");#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)#define read(x...原创 2018-09-29 23:46:42 · 148 阅读 · 0 评论 -
Codeforces 522D Closest Equals (线段树+DP+离线)*
题目链接:http://codeforces.com/problemset/problem/522/D#include<bits/stdc++.h>using namespace std;#define debug puts("YES");#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)#define read(x...原创 2018-09-30 10:00:16 · 180 阅读 · 0 评论 -
HDU 6444 Neko's loop (单调队列+带限制的最大子段和)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6444#include<bits/stdc++.h>using namespace std;#define debug puts("YES");#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)#define read(x...原创 2018-10-09 11:47:08 · 291 阅读 · 0 评论 -
HDU 5564 Clarke and digits (矩阵快速幂加速DP)*
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5564#include<bits/stdc++.h>using namespace std;#define debug puts("YES");#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)#define ll lon...原创 2018-11-09 16:31:58 · 155 阅读 · 0 评论 -
CodeForces - 115E Linear Kingdom Races (线段树优化DP)*
题目链接:http://codeforces.com/problemset/problem/115/E#include<bits/stdc++.h>using namespace std;#define debug puts("YES");#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)#define ll lon...原创 2018-11-10 16:43:30 · 212 阅读 · 0 评论 -
CodeForces - 82D Two out of Three (记忆化搜索+DP)*
题目链接:http://codeforces.com/problemset/problem/82/D#include<bits/stdc++.h>using namespace std;#define debug puts("YES");#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)#define ll long...原创 2018-11-13 18:39:01 · 288 阅读 · 0 评论 -
CodeForces 75D Big Maximum Sum (线段树辅助DP)
题目链接:http://codeforces.com/problemset/problem/75/D#include<bits/stdc++.h>using namespace std;#define debug puts("YES");#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)#define ll __i...原创 2018-12-05 07:44:52 · 160 阅读 · 0 评论 -
HDU 5863 cjj's string game (矩阵快速幂+DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5863#include<bits/stdc++.h>using namespace std;#define debug puts("YES");#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)#define ll lon...原创 2019-01-24 16:20:08 · 171 阅读 · 0 评论 -
Gym 101147F Bishops Alliance (树状数组+DP)
题目链接:http://codeforces.com/gym/101147/problem/F#include<bits/stdc++.h>using namespace std;#define debug puts("YES");#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)#define ll long lon...原创 2019-01-21 20:33:07 · 132 阅读 · 0 评论 -
HDU 6447 YJJ's Salesman (线段树优化DP)
#pragma comment(linker, "/STACK:102400000,102400000")#include<bits/stdc++.h>using namespace std;#define debug puts("YES");#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)#define lrt ...原创 2018-08-28 08:57:58 · 204 阅读 · 0 评论