![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
深搜
Strokess
懂的越少,想的越多。
展开
-
poj-2488 A Knight's Journey
#include#include#include#includeint map[50][50];int p, q;int move[8][2] = {-1, -2, 1, -2, -2, -1, 2, -1, -2, 1, 2, 1, -1, 2, 1, 2};int pn[50];char qn[50];int flag;void dfs(int num, char ch,原创 2015-10-04 18:11:41 · 413 阅读 · 0 评论 -
HDU 1010 Tempter of the Bone (搜索 + 奇偶剪枝)
HDU 1010深搜基础题,用到了奇偶剪枝。把map的奇偶性以01编号:0 1 0 1 0 1 1 0 1 0 1 0 0 1 0 1 0 1 1 0 1 0 1 0 0 1 0 1 0 1 可以发现从0走一步一定走到1,从1走一步一定走到0。也就是说,如果当前的狗所在的坐标与D的坐标奇偶性不一样,那么狗需要走奇数步。原创 2016-03-12 13:26:08 · 354 阅读 · 0 评论 -
POJ 2676 Sudoku (DFS回溯剪枝)
POJ 2676设置三个标记数组,分别是行的,列的和小正方型的。 行列比较好处理,至于小正方形,我刚开始是直接把每个格子遍历一遍,然后算出他们分别在哪一个小正方形内,最后存在一个数组里。这个方法虽然比较麻烦但是很好想,也不会花太多时间。做完之后学长又说了另一个好一些的办法。每个小正方形的编号k(1~9)恰好就等于(i - 1) / 3 * 3 + (j - 1) / 3 + 1。 有了这个式原创 2016-03-15 08:07:05 · 558 阅读 · 0 评论 -
HDU 1175 连连看 (搜索,dfs)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1175类似于迷宫问题,主要就在转折的处理上,在这里可以有一个强剪枝,具体见代码。参考博客:http://www.cnblogs.com/qiu520/p/3250167.html 感谢!#include #include #include #include using name原创 2016-04-25 14:07:28 · 380 阅读 · 0 评论 -
hdu 2181 哈密顿绕行世界问题 (dfs)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2181简单深搜,路径存储。#include #include #include #include #include using namespace std;int map[25][25];int vis[25];int path[25];int k;int m;void d原创 2016-04-27 21:38:45 · 389 阅读 · 0 评论 -
POJ 3373 Changing Digits
POJ 3373参考博客:http://blog.csdn.net/lyy289065406/article/details/6698787 解释得非常详细,大部分都能看懂。 感谢! http://www.cnblogs.com/fenshen371/p/3250109.html 感觉代码写的很漂亮。 感谢!感觉不太好做,加油吧。#include原创 2016-04-15 19:52:43 · 423 阅读 · 0 评论 -
Tyvj P1336 火车进栈 (深搜 + 出栈序列判断)
题目链接:http://www.tyvj.cn/p/1336#描述有n列火车按1到n的顺序从东方左转进站,这个车站是南北方向的,它虽然无限长,只可惜是一个死胡同,而且站台只有一条轨道,火车只能倒着从西方出去,而且每列火车必须进站,先进后出。(某生:不就是个栈吗?每次可以让右侧头火车进栈,或者让栈顶火车出站?占卜哥:闭嘴!)就像这样: 出站原创 2016-05-01 16:44:22 · 1730 阅读 · 0 评论 -
搜索水题 (排列组合)
nyoj 32题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=32组合数时间限制:3000 ms | 内存限制:65535 KB难度:3描述找出从自然数1、2、... 、n(0<n<10)中任取r(0<r<=n)个数的所有组合。输入输入n、r。输出按特定顺序输出所有组原创 2016-05-01 21:04:39 · 539 阅读 · 0 评论 -
POJ Anniversary Cake (dfs,神剪)
题目链接:http://poj.org/problem?id=1020题意:首行是t,下面t行每行是一个case,第一个数s表示给你一个边长为s的正方形大蛋糕,第二个数n表示把这个大蛋糕分成n块小正方形蛋糕,后面跟n个数表示这n个蛋糕的边长。问是否能刚好分完。是输出KHOOOOB! ,不是输出HUTUTU! 个人感觉这道搜索题有些难...看了别人的代码才了解了思路。参考原创 2016-05-12 21:39:53 · 820 阅读 · 0 评论 -
HDU 5113 Black And White (dfs、剪枝)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5113题意:N*M的棋盘,K种颜色,每种颜色有c[i]个(sigma(c[i]) = N*M),现在给棋盘染色,使得相邻的两个棋盘染成不同的颜色,并且把所有颜色用完。就像数独一样,因为棋盘比较小,可以想到用搜索写。不过爆搜会超时,需要一个强有力的剪枝。容易想到,当现在剩下的空格子数的原创 2016-10-22 18:49:59 · 511 阅读 · 0 评论 -
HDU 1241 Oil Deposits (搜索水题)
HDU 1241找连通集数量。注意第三个测试样例第一行后面多了一个空格,忽略即可。#include #include #include #include using namespace std;int m, n;char map[110][110];int dir[8][2] = {1, 1, 0, 1, 1, 0, -1, -1, -1, 0, 0, -1,原创 2016-03-11 18:45:59 · 485 阅读 · 0 评论 -
POJ 1011 Sticks (dfs + 厉害的剪枝)
POJ 1011拿2362的代码来交果断超时,研究了半天也没整出来。看了大神的剪枝方法,简直五体投地。详见代码。参考博客:http://blog.sina.com.cn/s/blog_7d3ee9f50100wiy4.html#include #include #include #include using namespace std;bool cmp原创 2016-03-10 18:45:08 · 392 阅读 · 0 评论 -
qduoj 生化危机
广搜#include #include #include #include #include #define MAXN 10010using namespace std;struct city { int id; int day;};int n, k;vector map[MAXN];queue q;int vis[MAXN];int ans[MAXN];i原创 2015-10-13 11:02:42 · 1513 阅读 · 0 评论 -
poj-3083 Children of the Candy Corn
#include#include#includeusing namespace std;char map[50][50];int dl[4][2] = {{0, -1}, {-1, 0}, {0, 1}, {1, 0}};int dr[4][2] = {{0, 1}, {-1, 0}, {0, -1}, {1, 0}};int dx[4] = {0, 1, 0, -1};int转载 2015-10-04 19:55:53 · 405 阅读 · 0 评论 -
hdu 2553 N皇后问题 (搜索)
HDU 2553不预处理会超时。。#include #include #include using namespace std;int map[11];int n;int sum;int ans[11];void dfs(int line) { if(line == n + 1) { sum++; return; } int i, j; int fl原创 2016-03-04 11:04:30 · 372 阅读 · 0 评论 -
poj 1014 Dividing (dfs???)
poj 1014待更新。。。#include #include #include #include #include using namespace std;int num[7];int flag;void dfs(int left) { if(flag) return; if(left == 0) { flag = 1; return; } int i;原创 2016-03-16 18:29:11 · 355 阅读 · 0 评论 -
蓝桥杯 7对数字 (dfs)
今有7对数字:两个1,两个2,两个3,...两个7,把它们排成一行。要求,两个1间有1个其它数字,两个2间有2个其它数字,以此类推,两个7之间有7个其它数字。如下就是一个符合要求的排列: 17126425374635 当然,如果把它倒过来,也是符合要求的。 请你找出另一种符合要求的排列法,并且这个排列法是以74开头的。 注意:只填写这个14位的整数,不能填写任何原创 2016-03-16 21:32:41 · 1305 阅读 · 0 评论 -
POJ 1190 生日蛋糕 (dfs + 神剪枝)
POJ 1190有三处剪枝,作为渣渣表示这题对我来说很有难度。题解也是看了好久才理解。首先,minv[i] 表示从上往下数第i层以及第i层以上的最小总体积,mins[i]表示从上往下数第i层以及第i层以上的最小总面积。仔细想想可以知道每层的半径和高度都取这一层的层数即可得到最小值。然后具体见代码。参考博客:http://www.cnblogs.com/rainyda原创 2016-03-29 16:17:46 · 964 阅读 · 0 评论 -
51nod 1384 全排列 (dfs)
51Nod 1384深搜入门,但有个小问题。。cout比printf快吗?#include #include #include #include using namespace std;char s[20];int a[20], ans[20], book[30], n;void dfs(int cnt) { int i; if(cnt == n) { for(i =原创 2016-03-05 16:39:38 · 882 阅读 · 1 评论 -
HDU 1312 Red and Black (dfs基础题)
HDU 1312#include #include #include #include #include using namespace std;int W, H;const int inf = 0x3f3f3f3f;int map[25][25], vis[25][25];int sx, sy;int dir[4][2] = {0, 1, 1, 0, 0, -1,原创 2016-04-01 16:41:55 · 407 阅读 · 0 评论 -
POJ 2362 Square (搜索 + 剪枝)
poj 2362发现了两个可以剪枝的地方,不过看大神的博客说还有更多可以剪枝的地方,能到十多毫秒,给跪了。我能写成这样已经很满足了,在剪枝之前,还是要先把深搜练熟练。祥见代码。#include #include #include #include using namespace std;int M, b, flag;int stick[30], book[3原创 2016-03-09 19:43:08 · 354 阅读 · 0 评论 -
PAT-A 1034. Head of a Gang (dfs)
题目链接:https://www.patest.cn/contests/pat-a-practise/1034刚开始用并查集发现不太好处理。。用搜索就好做多了。注意虽然路径数最多1000,但节点数可能2000,所以数组要开大不然段错误。#include #include #include #include #include #include using n原创 2016-11-24 17:12:35 · 626 阅读 · 0 评论