随笔分类 - 记忆化&动态规划
摘要:Aimee 显然的状压dp,但是还要考虑根节点。 那么把根节点也扔进去$f_{i,j}$表示i状态,有j层高。 转移的时候需要枚举i的子集,怎样保证子集合法? 可以预处理一个数组表示i状态最多可以扩展一次扩展成什么,来解决。 处理新增的部分的时候·,我们假定所有新点到根节点的距离都是我们当前枚举的k
阅读全文
摘要:Lisa 显然会形成一个图的结构,显然这玩意极有可能出现环 那咋办呢 从每一怪兽出发似乎都可以形成一个子问题。 每一个问题都是用自己所能到达的怪兽的花费来更新自己,如果自己更新了,就有机会更新自己的父亲 显然不会一直更新下去,这个环是有极限的。 所以好像出现了一个类似于spfa的结构 就是首先每个点
阅读全文
摘要:Lisa 显然状态压缩 然后,对于一个点集S,我们很容易求出这个点集可以形成的任意图$F_S$ 这个很容易预处理出来 然后呢,对于这个直接求联通的方案书并不容易,但是,可以用总方案减去不连通的方案数。 不连通的方案视为两个点集,一个点集随便,另一个点集必须联通。 所以在预处理完了以后,我们首先要做的
阅读全文
摘要:jennie 树上dp求直径的模板 #include<iostream> #include<cstdio> #include<cstring> #include<vector> using namespace std; int n; vector<int> v[100001]; int x,y; i
阅读全文
摘要:Archie 很显然的换根dp #include<iostream> #include<cstdio> #include<cstring> using namespace std; int son[100001]; int dis[100001]; int n; int a,b; int head[
阅读全文
摘要:Archie 记忆化搜索就好 #include<iostream> #include<cstdio> #include<algorithm> #include<cstring> using namespace std; int m; int x; int a[10005]; int n,k; int
阅读全文
摘要:Archie 还是很水的 注意一下边界 #include<iostream> #include<cstdio> #include<algorithm> #include<cstring> using namespace std; int n,m; int d[10001]; int dp[10005
阅读全文
摘要:dpdpdp Archie 很显然,每一层之间有最优子结构 那么,怎么转移呢,既然两个方向,那就加一维从哪里走 #include<iostream> #include<cstring> #include<algorithm> #include<cstdio> #define int long lon
阅读全文
摘要:[Archie]([P1006 NOIP2008 提高组] 传纸条 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)) 一步一步的走有点烦,何不走两步一次 #include<iostream> #include<cstdio> #include<algorithm> using na
阅读全文
摘要:FOGGY 记忆化搜索 改变每一个叶子节点,它的影响是线性的往根节点走 也就是说,如果一个父节点在这条路径上改变了,并且这种改变会影响到根节点那么应该标记, 同理,没有影响的改变 也就是说,标记某个节点的改变的影响 那么怎么具体搞呢 对于每一种操作,单独分析 \(O(n^2)\) #include<
阅读全文
摘要:Aimee 很显然的做法就是枚举每个点为源点然后树形dp \[ d_s[x]=\sum_{y\in son(x)} \left\{ \begin{aligned} min((D_s[y],c(x,y)))\quad degeree_y>1 \\ c(x,y) \quad\quad\quad\quad
阅读全文
摘要:Aimee "Doctor,你觉得问题在哪" "就在这里" 不能摘得桃树没有意义,一次摘得消耗是一样得,而且把时间和体力的消耗是一样的,那么也不用开二维了,记得给他留一点体力就可以了 剩下的就是个多重背包 # include<iostream> #include<cstdio> #include<c
阅读全文
摘要:Miku 悬线法: 对于每一个点,我们以这个点为矩形的最低点,然后向左右检查最大扩展位置,然后向上找在此情况下的最大高度 #include<cstdio> #include<algorithm> #include<cstring> #include<iostream> using namespace
阅读全文
摘要:Aimee 显然是可以继承的 #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<string> #include<algorithm> #include<cmath> using name
阅读全文
摘要:[Aimee](P1855 榨取kkksc03) 很简单的dp #include<iostream> #include<cstring> using namespace std; int n,m,t; int mi[1000]; int ti[1000]; int dp[201][301][201]
阅读全文
摘要:[Aimee](https://www.luogu.com.cn/problem/P1474) 显然是个背包 #include<iostream> #include<cstdio> #define int long long using namespace std; int n,v; int f[1
阅读全文
摘要:Aimee 非常显然 #include<iostream> #include<cstring> using namespace std; int n; int h[1000001]; long long dp[1000001][2]; int main(){ cin>>n; memset(dp,0x
阅读全文
摘要:Aimee 一道非常水的分组背包求方案数 字典序这个东西要谨慎处理 #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int n,m; int dp[20][2
阅读全文
摘要:AImee \(dp_{i,j}表示第i天到达第j个城市\) 反正是线性的,那么要不是早就到了j在那休息,要不就是上一天从上一座城市过来 #include<iostream> #include<cstdio> #include<cstring> using namespace std; int d[
阅读全文
摘要:Aimee 很显然的区间dp 字符和数字之间使用map大法进行转换即可 经典边界问题以及一点点暴力判断和优化 #include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #include<map> using n
阅读全文