随笔分类 - DFS
摘要:题意:给一棵N个点的树,对应于一个长为N的全排列,对于排列的每个相邻数字a和b,他们的贡献是对应树上顶点a和b的路径长,求所有排列的贡献和。思路:对于任意的xy,其在全排列中相邻的组合数是(n-1)!*2,这样题目意思就明了了,求一棵树中任意两点距离和,边上有权重。贡...
阅读全文
摘要:水题。#includeusing namespace std;#define inf 0x3f3f3f3f#define ll long longconst int maxn=200005;const double eps=1e-8;const double PI =...
阅读全文
摘要:水题。#include#include#include#include#include#include#include#include#include#include#include#include#include#include#includeusing names...
阅读全文
摘要:题意:一笔画画出圣诞老人的房子,并按字典序输出。思路:从1点DFS遍历图(八条边需要9画)#includeusing namespace std;#define inf 0x3f3f3f3f#define ll long longconst int maxn=2000...
阅读全文
摘要:题意:找连通的积水(上下左右和对角线都算)的总数。思路:从任意的W开始,不停的把邻接的部分用'.'代替,1次DFS就可以把与W连通的全部换成‘.’,总共进行的DFS次数就是结果。#include#include#include#include#include#incl...
阅读全文
摘要:num--忘了写。。#includeusing namespace std;int m[10][10],vis[10];int n,k;int cas=0;int num;void dfs(int c){ if(num==k) { cas++...
阅读全文

浙公网安备 33010602011771号