随笔分类 -  树上dp

摘要:jennie 树上dp求直径的模板 #include<iostream> #include<cstdio> #include<cstring> #include<vector> using namespace std; int n; vector<int> v[100001]; int x,y; i 阅读全文
posted @ 2021-07-25 20:41 Simex 阅读(30) 评论(0) 推荐(0) 编辑
摘要: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 阅读全文
posted @ 2021-06-20 16:33 Simex 阅读(56) 评论(0) 推荐(0) 编辑
摘要:Aimee 这是个dp?不过没有必要用dp 毕竟显然距离为2中间一定要经过一个点,那枚举中间点即可 之后显然假设一个点所有相邻的点的点权为集合A=a1,a2,a3······ak 显然对于这个点,和就是11aiaj|i=j 那么这样上 阅读全文
posted @ 2021-02-21 20:54 Simex 阅读(75) 评论(0) 推荐(0) 编辑
摘要:Aimee 很简单的树上dp 一维就够了 #include<iostream> #include<cstdio> #include<cstring> using namespace std; int n; int x,y; int zn[160001]; struct e{ int to; int 阅读全文
posted @ 2020-10-31 18:57 Simex 阅读(79) 评论(0) 推荐(0) 编辑
摘要:Miku 很好的坑题,务必注意因为负边权和求路径的问题,这里需要同时用到两种方法,搜索和dp。 对于原来的情况,事实上就是每一条边都要走两次,(毕竟你还要回来啊) 但是你要是建了一条边,就会形成一个环,那么这辆车就可以直接走回去了(沿着这个圈回到出发点,也就是说,少了一条边长度的距离) 那么怎么搞呢 阅读全文
posted @ 2020-10-17 19:42 Simex 阅读(95) 评论(0) 推荐(1) 编辑
摘要:Miku 可以用树上dp解决 dpi,j表示以i为根的子树在模三意义下到i的距离为j的点有几个 然后根据乘法原理搞一波 #include<iostream> #include<cstdio> #include<algorithm> using namespace std; int n; i 阅读全文
posted @ 2020-08-22 20:38 Simex 阅读(79) 评论(0) 推荐(0) 编辑
摘要:Miku 从叶子结点开始,自下而上得跑分组背包 #include<iostream> #include<cstdio> #include<algorithm> #include<cstring> using namespace std; int n,m; int s[301]; struct b{ 阅读全文
posted @ 2020-08-06 22:29 Simex 阅读(145) 评论(0) 推荐(0) 编辑
摘要:Miku 或许dp起来有点麻烦 那何不记忆化呢 #include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #include<cmath> using namespace std; int head[100001 阅读全文
posted @ 2020-08-06 22:26 Simex 阅读(102) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示