![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
dfs
丶沙鸥
这个作者很懒,什么都没留下…
展开
-
2021CCPC网络赛重赛 _ 1011 _ HDU7136 _ Jumping Monkey 并查集,重建树
原题链接 转载博客 写的很好了,这里只做记录:D 贴个代码 #include<bits/stdc++.h> #define LL long long #define INF INT64_MAX #define MOD 998244353 #define ls rt << 1 #define rs rt << 1 | 1 using namespace std; typedef pair<int,int>pa; const int N = 1e5+7; int原创 2021-10-14 20:14:51 · 116 阅读 · 0 评论 -
Codeforces Global Round 15 1552D. Array Differentiation 思维好题 场景转换(建边/dp)
原题链接 题意: 给出n个数a1…an,问能否找到n个数b1…bn使得任意一个ai可以由b数组中两个数相减得到。 思路: 很容易发现x+1个bi是可以随意构造出x个ai的,一个b0=0,其他bi=bi-1 + a[i] 就可以了,所以只要这x+1个bi中还可以构造出一个其他ai就是可行的。 现在的问题就变成了是否存在一段ai的和等于另一段没有重复元素的ai的和,如图所示,有一个像这样环就是可以的。 这是dfs写的,还有一种写法是用三进制枚举,=每一个ai是加还是减或者跳过,然后看有没有sum==0的情况,原创 2021-09-08 15:19:12 · 212 阅读 · 3 评论 -
hud6986 Kanade Loves Maze Designing 简单dfs
原题链接 #include<bits/stdc++.h> #define LL long long #define INF INT64_MAX #define MOD 998244353 #define ls rt << 1 #define rs rt << 1 | 1 using namespace std; typedef pair<int,int>pa; const int N = 100005; const int b = 19560929; vect原创 2021-08-27 16:48:38 · 404 阅读 · 0 评论 -
POJ3321 Apple Tree dfs序+树状数组
原题地址 题意:给一颗根为1的树,节点数为n,一开始每个节点上有一颗苹果,现有两个操作: 1.Q x,输出x的子树上的苹果个数。 2.C x,如果x点有苹果就拿走,没有就长一个出来。 m次操作。 思路:用dfs序把树上的节点转换成区间形式,然后用树状数组或者线段树维护和查询,模板题。 #include <iostream> #include <stdio.h> #include<cmath> #include <cstdio> #include<algo原创 2021-08-08 21:29:03 · 119 阅读 · 0 评论