深 / 广搜
文章平均质量分 66
大白菜MC
这个作者很懒,什么都没留下…
展开
-
简单深搜广搜基本模板
简单搜索DFS:剪枝,条件容易超时,超时后基本就是剪枝的问题/无限递归?,或者用广搜试试?模板(自己的理解)int n,m;//一般输入的行列数/边界int mov[4][2] = {1,0,-1,0,0,1,0,-1};int vis[N][N],mapp[N][N];//vis初始化应该在主函数int s = 0;//记录步数时间什么的void DFS(int x,int y){ if(x = endx && y == endy)//满足条件原创 2021-04-12 21:34:21 · 1995 阅读 · 0 评论 -
Nightmare(BFS)
Problem DescriptionIgnatius had a nightmare last night. He found himself in a labyrinth with a time bomb on him. The labyrinth has an exit, Ignatius should get out of the labyrinth before the bomb explodes. The initial exploding time of the bomb is set to原创 2021-03-19 20:57:57 · 126 阅读 · 0 评论 -
逃离迷宫(bfs)
Problem Description 给定一个m × n (m行, n列)的迷宫,迷宫中有两个位置,gloria想从迷宫的一个位置走到另外一个位置,当然迷宫中有些地方是空地,gloria可以穿越,有些地方是障碍,她必须绕行,从迷宫的一个位置,只能走到与它相邻的4个位置中,当然在行走过程中,gloria不能走到迷宫外面去。令人头痛的是,gloria是个没什么方向感的人,因此,她在行走过程中,不能转太多弯了,否则她会晕倒的。我们假定给定的两个位置都是空地,初始时,gloria所面向的方向未定,她可以选择4原创 2021-03-16 21:13:47 · 221 阅读 · 0 评论 -
棋盘问题(深搜)
Problem Description在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别。要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有可行的摆放方案C。Input输入含有多组测试数据。 每组数据的第一行是两个正整数,n k,用一个空格隔开,表示了将在一个n*n的矩阵内描述棋盘,以及摆放棋子的数目。 n <= 8 , k <= n 当为-1 -1时表示输入结束。 随后的n行描述了棋盘的形状:每行有n个字符,原创 2021-02-01 10:36:07 · 1255 阅读 · 0 评论 -
Anniversary Cake (深搜)
Anniversary CakeProblem DescriptionNahid Khaleh decides to invite the kids of the “Shahr-e Ghashang” to her wedding anniversary. She wants to prepare a square-shaped chocolate cake with known size. She asks each invited person to determine the size of th原创 2021-01-17 11:04:43 · 191 阅读 · 0 评论 -
Red and Black (深搜)
Red and BlackProblem DescriptionThere is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adjacent tiles. But he can’t move on red tiles, h原创 2021-01-17 10:41:08 · 243 阅读 · 0 评论