DFS
文章平均质量分 63
Werky_blog
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
树的遍历 PAT 1004
题目地址:https://www.patest.cn/contests/pat-a-practise/1004 C语言实在有点麻烦 /* Member(Vertex):表示一个家庭成员,我使用了两个结构成员: level,表示这个人在家谱中的辈分,最高的辈分是0,辈分越低,level越大 child,指向Child结构变量,即链表的第一个节点 Child(Edge):表示亲子关系,也转载 2017-06-04 16:09:57 · 340 阅读 · 0 评论 -
L2-013 红色警戒(强连通分量)
题目:https://www.patest.cn/contests/gplt/L2-013#include<bits/stdc++.h> using namespace std; const int maxn=505; //思路:把原来有几个连通量求出来,赋为1后有几个求出来,增加的话警告 bool vis[maxn],v[maxn][maxn]; int n; void dfs(in...原创 2018-03-08 20:49:56 · 308 阅读 · 0 评论 -
poj 1664 放苹果(dfs/dp/母函数)
题目:http://poj.org/problem?id=1664Description把M个同样的苹果放在N个同样的盘子里,允许有的盘子空着不放,问共有多少种不同的分法?(用K表示)5,1,1和1,5,1 是同一种分法。Input第一行是测试数据的数目t(0 <= t <= 20)。以下每行均包含二个整数M和N,以空格分开。1<=M,N<=10。Output对输入的每组数...原创 2018-01-08 16:01:36 · 341 阅读 · 0 评论 -
hdu 1176 免费馅饼
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1176 免费馅饼 Problem Description 为了使问题简化,假设在接下来的一段时间里,馅饼都掉落在0-10这11个位置。开始时gameboy站在5这个位置,因此在第一秒,他只能接到4,5,6这三个位置中其中一个位置上的馅饼。问gameboy最多可能接到多少个馅饼?(假原创 2018-01-07 18:02:44 · 277 阅读 · 0 评论 -
poj1315 变形N皇后
题目:http://poj.org/problem?id=1315 题意:X是墙,可以挡着防止相互攻击 /* step++,x=step/n,y=step%n一行一行的搜,搜到可行的位置,不用标记false,往上和往左找就行, 再一行一行的搜,不行就回溯,直到第一行找完 其实第一颗棋子试到了第二行就完事了,不过为了好写都找了吧 */ #include #include using namesp原创 2018-01-05 21:38:09 · 328 阅读 · 0 评论 -
hdu 1010 Tempter of the Bone(dfs+枝剪)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1010 题意:n*m的地图,规定恰好在第t步到达终点'D',起点是‘S’,墙是‘X’ 思路:还是走迷宫的题,每次上下左右走,暴力所有情况,找到恰好是t步的路径,每次回溯再回到初始状态。 但还有一个奇偶枝剪,意思就是要求的最短路径是|ex-sx|+|ey-sy|,若要到达终点,必须多走偶数步。原创 2017-12-19 15:25:58 · 169 阅读 · 0 评论 -
hdu 5113 Black And White(dfs+枝剪)
题目;http://acm.hdu.edu.cn/showproblem.php?pid=5113 参考自:http://blog.youkuaiyun.com/howardemily/article/details/53022562 跟四色定理没什么关系,可以用好多种颜色,但有使用次数限制。 有一个包含从1到K一共K种颜色的N×M棋盘,使得任意两个相邻的区块不能有相同的颜色 (如果它们的转载 2017-12-18 21:39:16 · 149 阅读 · 0 评论 -
POJ 1129 Channel Allocation (dfs+四色定理)
题目:http://poj.org/problem?id=1129 跟竞赛宝典上那个题一样,给出一个区域,后面是相连的区域,求最小染色数。 由四色定理可知,最大是4种,可作为一种枝剪方法。 dfs: #include #include #include using namespace std; int mp[30][30],v[30],n,flag; void dfs原创 2017-12-18 14:32:46 · 291 阅读 · 0 评论 -
hdu 2553 经典N皇后
题目:http://acm.hdu.edu.cn/showproblem.php?pid=2553 思路: 位运算优化,最优雅的写法。 #include using namespace std; int lim,sum; void dfs(int row,int left,int right){ int pos,p; if(row!=lim){ pos=li原创 2017-12-22 17:18:59 · 201 阅读 · 0 评论 -
poj 3768 分形图
题目:http://poj.org/problem?id=3768 题意:分形图,用C++就过了,实在不想看了 #include #include #include int m; char mp[3005][3005],mo[6][6]; int quick_pow(int x, int n){ //快速幂 int ans=1; while(n){ if(原创 2017-12-21 22:32:56 · 318 阅读 · 0 评论 -
poj 2083 Fractal (dfs 分形图)
题目:http://poj.org/problem?id=2083 题意:递归把分形图输出出来,显然面积是3^n-1*3^n-1 //#include #include #include #include //using namespace std; char mp[731][731]; void dfs(int n,int x,int y){ if(n==1){ m原创 2017-12-21 12:09:45 · 517 阅读 · 0 评论 -
hdu 1372 Knight Moves(骑士遍历/跳马问题)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1372 题意:跳马走法,给出8*8的格子,求起点到终点的最小步数 思路:一个枝剪:马走的最大步数小于等于起终点横坐标或纵坐标相差较大的一个,,, (其实横纵坐标间隔相加除以2即可) 玩了这么多年象棋竟然不知道。 #include using namespace std; int s原创 2017-12-20 23:33:04 · 700 阅读 · 0 评论 -
hdu 1455 sticks (dfs+枝剪)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1455 题意:给一些木条长度,原本是相同长度的木条掰断而成,求重新组成的最短长度; 思路:还是dfs暴力枚举,枝剪一些就行,虽然前后一起找快一些,但不会写。 #include using namespace std; int a[65],sum,num,lenn,n,ans; bool flg[65]原创 2017-12-20 17:26:03 · 172 阅读 · 0 评论 -
hdu 2489 Minimal Ratio Tree(prim+dfs)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=2489 算最小Ratio,edge weight可以由prim算出,然后dfs暴力枚举n个点中m个点的最小ratio。 /* prim应用错误:是将m个点生成最小树,而不是那n个! temp[i]记录的是编号; */ #include #include #include #include #in原创 2017-09-26 22:15:01 · 193 阅读 · 0 评论 -
pat 甲级1013 DFS求强连通分量
vitally!题目:https://www.patest.cn/contests/pat-a-practise/1013#include<cstdio> #include<string> #include<algorithm> using namespace std; int v[1005][1005]; bool visit[1005]; int N; ...转载 2017-09-07 17:58:40 · 410 阅读 · 0 评论 -
hdu red and black
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1312 DFS: #include int h,w; char z[21][21]; int dfs(int i,int j){ if(ih-1||jw-1) return 0; if(z[i][j]!='#'){ z[i][j]='#';原创 2017-06-03 10:34:13 · 264 阅读 · 0 评论 -
L2-016 递归模拟
题目:https://www.patest.cn/contests/gplt/L2-016不错的模拟,就是要注意标记父母的性别。#include <bits/stdc++.h> using namespace std; struct node{ char sex; int fa=-1,ma=-1; }man[100005]; bool find(int a,int ...原创 2018-03-10 20:30:51 · 178 阅读 · 0 评论
分享