
DP
poursoul
这个作者很懒,什么都没留下…
展开
-
【URAL】1057 Amount of Degrees 数位DP
传送门:【URAL】1057 Amount of Degrees原创 2014-10-31 11:14:30 · 679 阅读 · 0 评论 -
【HDU】5208 Where is Bob 【DP】
传送门:【HDU】5208 Where is Bob题目分析:设状态为dp[cur][l1][r1][l2][r2],cur表示当前二进制位的位置,l1表示第一个人的数的下界,r1表示第一个人的数的上界,l2表示第二个人的数的下界,r2表示第二个人的数的上界。l1,r1,l2,r2都是01变量,对于第一个数,如果数卡着下界不能变小时l1置为0,否则l1置为1表示可以变小。第一个数的原创 2015-04-19 19:38:16 · 1170 阅读 · 1 评论 -
【BZOJ】3572: [Hnoi2014]世界树【虚树DP】
传送门:3572: [Hnoi2014]世界树my code:#include #include #include #include using namespace std ;typedef long long LL ;typedef unsigned long long ULL ;typedef pair pii ;#define rep( i , a ,原创 2015-04-21 12:48:13 · 1142 阅读 · 0 评论 -
【BZOJ】2286: [Sdoi2011消耗战【虚树DP】
传送门:【BZOJ】2286: [Sdoi2011消耗战my code:#include #include #include using namespace std ;typedef long long LL ;#define rep( i , a , b ) for ( int i = ( a ) ; i < ( b ) ; ++ i )#define For(原创 2015-04-21 21:17:10 · 831 阅读 · 0 评论 -
【codeforces】543D. Road Improvement【树形DP】
传送门:【codeforces】543D. Road Improvement题目分析:dp方程很水= =,设dp[u]为以u为根的子树的合法方案数。对于一个节点u考虑所有儿子v,则有dp[u]=∏\prod(dp[v]+1)。考虑以1为根,那么一次树形dp以后我们就得到了1为根的方案数,接下来我们还需要一次dp来换根。由于0的逆元不存在,所以本题我们简单的用逆元是错误的!然后我们考虑前缀积以及后缀积原创 2015-05-08 23:36:11 · 1216 阅读 · 0 评论 -
【HDU】5290 Bombing plan 【树形DP】
传送门:【HDU】5290 Bombing planmy code:my~~code:#include <stdio.h>#include <string.h>#include <vector>#pragma comment(linker, "/STACK:16777216")#include <algorithm>using namespace std ;typedef long lo原创 2015-07-27 15:42:26 · 1391 阅读 · 0 评论 -
【HDU】5293 Tree chain problem【DP+LCA】
传送门:【HDU】5293 Tree chain problemmy code:my~~code:/************************************************************************* > File Name: F.cpp > Author: poursoul > Created Time: 2015年07月22原创 2015-07-27 15:48:50 · 670 阅读 · 0 评论 -
【HDU】5313 Bipartite Graph【二分图+背包】
传送门:【HDU】5313 Bipartite Graph复杂度:O(NN√logN32)O(\frac{N\sqrt{N}\log{N}}{32}) 方法:多重背包bitset优化my code:my~~code:#include <stdio.h>#include <string.h>#include <bitset>#include <algorithm>using namespa原创 2015-07-27 16:13:31 · 852 阅读 · 0 评论 -
【HDU】5309 JRY is Fighting【DP】
传送门:【HDU】5309 JRY is Fightingmy code:my~~code:#include <bits/stdc++.h>using namespace std ;typedef long long LL ;const int MAXN = 500005 ;int a[MAXN] ;int R[MAXN] ;int d[MAXN] ;int nxt[MAXN] ;int原创 2015-07-27 16:05:25 · 1228 阅读 · 0 评论 -
【HDU】5291 Candy Distribution 【DP+打标记】
传送门:【HDU】5291 Candy Distributionmy code:my~~code:/************************************************************************* > File Name: D.cpp > Author: poursoul > Created Time: 2015年07月22原创 2015-07-27 15:44:58 · 1217 阅读 · 0 评论 -
【HDU】5304 Eastest Magical Day Seep Group's Summer【环dp+生成树计数】
传送门:【HDU】5304 Eastest Magical Day Seep Group’s Summermy code:my~~code:#include <bits/stdc++.h>using namespace std ;typedef long long LL ;#define clr( a , x ) memset ( a , x , sizeof a )const int MAXN原创 2015-07-27 15:58:56 · 884 阅读 · 0 评论 -
【一道不知道名字的题】AC自动机+dp
太懒了,好久没写题解了。Time Limit : 3000/3000ms (Java/Other) Memory Limit : 65535/65536K (Java/Other)Total Submission(s) : 34 Accepted Submission(s) : 8Problem DescriptionLet Str be a long string原创 2015-04-07 12:52:01 · 898 阅读 · 0 评论 -
【codeforces】494D. Birthday 【树型DP+离线tarjan求LCA】
传送门:【codeforces】494D. Birthday题目分析:首先明确一点,平方和是可以递推的!1.我们第一次dfs,求出从一个点到其子树的所有点的距离的平方和。大体是保存三个变量来递推,设u的子树上点的个数cnt,到子树上点的距离和sum,到子树上点的距离平方和sqr,每次dfs完一个儿子v以后:dp[u].cnt+=dp[v].cntdp[u].sum+=d原创 2014-12-14 14:21:37 · 1278 阅读 · 0 评论 -
【HDU】3271 SNIBB 数位DP
传送门:【HDU】3271 SNIBB原创 2014-10-31 20:23:24 · 1062 阅读 · 0 评论 -
【HDU】4352 XHXJ's LIS 数位DP
传送门:【HDU】4352 XHXJ's LIS题目分析:dp[原创 2014-11-18 19:08:43 · 1115 阅读 · 0 评论 -
【codeforces】Codeforces Round #277.5 (Div. 2)
传送门:【codeforces】Codeforces Round #277.5 (Div. 2)A:原创 2014-11-18 13:19:08 · 1091 阅读 · 1 评论 -
【HDU】4616 Game 树型DP
传送门:【HDU】4616 Game原创 2014-11-21 16:16:16 · 1124 阅读 · 0 评论 -
【HDU】3886 Final Kichiku “Lanlanshu” 数位DP
传送门:【HDU】3886 Final Kichiku “Lanlanshu”题目分析:要求满足所给字符串原创 2014-11-21 18:55:20 · 803 阅读 · 0 评论 -
【SGU】104. Little shop of flowers DP
传送门:【SGU】 104. Little shop of flowers题目分析:dp[i][原创 2014-11-04 19:51:07 · 796 阅读 · 0 评论 -
【codeforces】2014-2015 ACM-ICPC, Central Europe Regional Contest (CERC 14) F Vocabulary【dp】
传送门:【codeforces】2014-2015 ACM-ICPC, Central Europe Regional Contest (CERC 14) F Vocabulary题目分析:蒽。。。。这个dp嘛其实也是满简单易懂的,就是要考虑的地方略多一点。。。设字典序最小的为a串,中间的为b串,最大的为c串。首先我们预处理出'?'个数在前i个字符位置的个数num[原创 2014-12-19 22:24:08 · 2073 阅读 · 0 评论 -
【HDU】5141 LIS again 在普通nlogn求LIS的基础上稍作修改
传送门:【HDU】5141 LIS again题目分析:我们枚举所有点R作为终点,求【1,R】内有多少个符合条件的L使得【L,R】的lis等于【1,n】的LIS。为每个终点R,找到能得到LIS的最右端的起点L,这样从1~L这段区间内的点都是可以和R构成lis等于LIS的合法区间的。这个我们就求LIS的时候顺便保存二分得到的数组中每个位置对应最右端的起点,然后插入或替换点的时候就从上一个原创 2014-12-08 11:27:31 · 1009 阅读 · 1 评论 -
【codeforces】2014-2015ACM-ICPC CERC 14 Problem G: Virus synthesis 【Palindromic Tree+DP】
传送门:【codeforces】2014-2015ACM-ICPC CERC 14 Problem G: Virus synthesis题目分析:首先我们构造回文树,然后我们只考虑长度为偶数的回文串,长度为奇数的回文串总可以通过长度为偶数的回文串然后加上剩下的所需字符构成(当然这个偶数回文串的长度可以是0,此时这个奇数回文串的构造次数就是其长度)。对于一个偶数长度回文串u,假设其构造次原创 2014-12-24 22:01:08 · 2129 阅读 · 0 评论 -
【codeforces】Codeforces Round #284 (Div. 1) 【题解】
传送门:【codeforces】Codeforces Round #284 (Div. 1)498A题目等价于给N条直线,如果两个点分别在直线两侧,则++cnt,最后的答案就是cnt的值。方法就是带入点的坐标到直线方程ax+by+c中看得到的两个值的乘积是否小于0,小于0则++cnt。而我,用了十分蠢的方法!将直线变成线段,将所给两个点连接,这样题目就变成求与所给两点构成的线段原创 2014-12-25 21:45:42 · 1910 阅读 · 5 评论 -
【HDU】5362 Just A String【生成函数dp】
传送门:【HDU】5362 Just A String这题整整想了我两天= =终于搞出来了。 一开始写出O(N3)O(N^3)的dp,转化一下,可以搞出一个生成函数,然后展开生成函数可以发现系数是二项式,然后对于枚举的长度i取出第i项就可以了。有个优化是发现奇数长度的回文串和偶数长度的回文串的贡献是一样的,所以不需要特殊处理奇数了。my code:my~~code:#include <bits/原创 2015-08-08 10:41:57 · 1474 阅读 · 0 评论 -
【HDU】5370 Tree Maker 【树dp】
传送门:【HDU】5370 Tree Makermy code:my~~code:#include <bits/stdc++.h>using namespace std ;typedef long long LL ;#define clr( a , x ) memset ( a , x , sizeof a )const int MAXN = 505 ;const int mod = 1e9原创 2015-08-12 11:44:24 · 940 阅读 · 0 评论 -
【HDU】5932.Backpack on Tree 【贪心+背包】
题目链接:Backpack on Tree每层,对价值除以花费的斜率从大到小排序,然后贪心到恰好大于询问的容量t,接下来开始dp。 设dp[i][j]表示贪心到第i个物品,取出里面花费为j的最小价值。dp2[i][j]表示斜率从小到大(即从右到左)取出花费为j的最大代价。 假设现在贪心得到的价值为t2(因为最大花费为5,所以t2-t<5),然后我枚举从贪心的解里面丢掉花费为x的最小价值dp[i]原创 2016-10-08 10:51:52 · 1212 阅读 · 0 评论 -
【HDU】5837 Robots【DP】
题目链接:Robots旋转45度坐标系,x’=x+y,y’=x-y,然后横纵坐标变成独立问题,接下来dp。#include <bits/stdc++.h>using namespace std ;typedef long long LL ;#define clr( a , x ) memset ( a , x , sizeof a )const int MAXN = 205 ;const int原创 2016-10-08 11:54:11 · 586 阅读 · 0 评论 -
【PA】PA2014Final Wykładzina【单调栈+双指针+均摊分析】
题目链接:【PA】PA2014Final Wykładzina均摊分析可知复杂度O(N2)O(N^2)#include <bits/stdc++.h>using namespace std ;typedef long long LL ;typedef pair < int , int > pii ;typedef unsigned long long ULL ;#define clr( a ,原创 2016-11-06 19:37:40 · 553 阅读 · 0 评论 -
【HDU】5789 Permutation【dp】
题目链接:Permutation#include <bits/stdc++.h>using namespace std ;typedef long long LL ;typedef vector < int > vi ;typedef map < LL , int > mpvi ;#define clr( a , x ) memset ( a , x , sizeof a )const int原创 2016-10-08 12:42:23 · 617 阅读 · 0 评论 -
【HDU】5771 Turn Game 【dp套dp】
题目链接:Turn Gamedp套dp。逐行dp,枚举每一行的状态,向下转移。状态即每一列上是否有列覆盖住这一行。#include <bits/stdc++.h>using namespace std ;typedef long long LL ;typedef vector < int > vi ;typedef map < LL , int > mpvi ;#define clr( a ,原创 2016-10-08 12:52:07 · 1108 阅读 · 0 评论 -
【HDU】5766 Filling【轮廓线dp+burnside引理】
题目链接:Filling轮廓线dp出整个的,一半的,1/4的,然后用burnside引理去重。#include <bits/stdc++.h>using namespace std ;typedef long long LL ;typedef pair < int , int > pii ;#define clr( a , x ) memset ( a , x , sizeof a )const原创 2016-10-08 12:57:50 · 801 阅读 · 0 评论 -
【HDU】5426 Rikka with Game【DP】
题目链接:【HDU】5426 Rikka with Game#include <bits/stdc++.h>using namespace std ;typedef long long LL ;#define clr( a , x ) memset ( a , x , sizeof a )const int MAXN = 100005 ;const int MAXE = 200005 ;con原创 2016-11-01 11:22:42 · 886 阅读 · 0 评论 -
【HDU】5436 Transmigration tree【树链剖分+dp+rmq】
题目链接:【HDU】5436 Transmigration tree#pragma comment(linker, "/STACK:16777216")#include <stdio.h>#include <string.h>#include <vector>#include <algorithm>using namespace std ;typedef long long LL ;#de原创 2016-11-01 11:30:19 · 668 阅读 · 0 评论 -
【codeforces】gym 101137 E - Economy Printing【dp】
题目链接:【codeforces】gym 101137 E - Economy Printing对值排序,会发现只有最后两个元素有用,枚举他们是被压缩在哪种类型,接在哪个数后面,dp即可。#include <bits/stdc++.h>using namespace std ;typedef pair < int , int > pii ;#define clr( a , x ) memset (原创 2016-11-02 20:42:56 · 768 阅读 · 0 评论 -
【codeforces】gym 101138 K. The World of Trains【前缀和优化dp】
题目链接:K. The World of Trains记录一个横着的前缀dp和以及斜着的前缀dp,复杂度O(n2)O(n^2)#include <bits/stdc++.h>using namespace std ;typedef pair < int , int > pii ;typedef long long LL ;#define clr( a , x ) memset ( a , x ,原创 2016-10-31 19:09:52 · 987 阅读 · 0 评论 -
【topcoder】SRM696 div1 550 Clicounting【折半枚举求最大团+高维前缀最大值】
题目链接:【topcoder】SRM696 div1 550 Clicounting最大团可以n2nn2^n搞,然后对这个可以做高维前缀最大值。就可以得到以某个状态的子集构成的最大团的大小。然后显而易见可以折半爆搜,然后瞎几把搞就好了。#include <bits/stdc++.h>using namespace std ;#define clr( a , x ) memset ( a , x ,原创 2016-11-07 22:27:37 · 873 阅读 · 0 评论 -
【codeforces】730F. Ber Patio【dp】
题目链接:【codeforces】730F. Ber Patiodp[i][j]dp[i][j]表示买了前ii件物品,另外得到了jj个代币所用的最小现金数。买第i+1i+1件前还剩多少代币可用总代币-买了前ii件另外获得的代币(即dp[i][j]dp[i][j]的jj)-买前ii件要花多少钱(即∑ik=1ak\sum_{k=1}^{i}a_k)+买前ii件用了多少现金(即dp[i][j]dp[i][原创 2016-11-05 11:34:42 · 633 阅读 · 0 评论 -
【HDU】5470 Typewriter 【后缀自动机+dp】
传送门:【HDU】5470 Typewritermy code:my~~code:#include <bits/stdc++.h>using namespace std ;typedef long long LL ;#define clr( a , x ) memset ( a , x , sizeof a )const int MAXN = 100005 ;const int N = 26原创 2015-09-29 22:20:29 · 1852 阅读 · 1 评论 -
【FZU】Problem 2217 Taxi 【暴力状压dp】
传送门:【FZU】Problem 2217 Taximy code:my~~~code:///*#include <stdio.h>#include <string.h>#include <algorithm>//*///#include <bits/stdc++.h>using namespace std ;typedef long long LL ;#define clr( a原创 2015-12-28 18:21:14 · 1178 阅读 · 0 评论 -
【HDU】5743 Join The Future【dp】
题目链接:Join The Future并查集压缩相等的点,发现最多只会有20个大于1的联通块,状压dp即可#include <bits/stdc++.h>using namespace std ;typedef long long LL ;#define clr( a , x ) memset ( a , x , sizeof a )const int MAXN = 42 ;const int原创 2016-10-08 19:59:02 · 512 阅读 · 0 评论