
DFS
HPU2_2
这个作者很懒,什么都没留下…
展开
-
Red and Black
There 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'...原创 2018-08-01 20:17:04 · 188 阅读 · 0 评论 -
洛谷 P1040 加分二叉树
题目链接:https://www.luogu.org/problemnew/show/P1040思路:寻找最大的权值,可以是DP,也可以用DFS来进行搜索,DFS(L, R)表示从L到R的最大权值的子树。那么就可以写出递归 :temp = DFS(L, i - 1) * DFS (i + 1, R) + a[i]这个递归就可以计算出的最大权值。用 num[L][R] 保存下来,同时再用另外一...原创 2018-11-06 22:44:44 · 142 阅读 · 0 评论 -
洛谷P1162 填涂颜色【深度搜索】
题目链接:https://www.luogu.org/problemnew/show/P1162这道题主要是如何区分在“1”内部和在“1”外部的“0”。刚开始我想的是遍历用一组数据标记状态来区分。但是这样是不能区分“1”内外的“0”的。然后呢就是能不能先把“1”外围的“0”全部都标记出去,只要“0”处于“1”的外边,那么从外围开始搜索就必然能够搜索的这个“0”并且标记它。这时候就要有一点技巧的进...原创 2018-10-30 22:00:28 · 162 阅读 · 0 评论 -
洛谷 P1011 - 单词方阵
题目描述给一n \times nn×n的字母方阵,内可能蕴含多个“yizhong”单词。单词在方阵中是沿着同一方向连续摆放的。摆放可沿着 88 个方向的任一方向,同一单词摆放时不再改变方向,单词与单词之间可以交叉,因此有可能共用字母。输出时,将不是单词的字母用*代替,以突出显示单词。例如:输入输出格式输入格式:第一行输入一个数nn。(7 \le n \le 1007≤n≤100)。第二...原创 2018-10-01 20:27:42 · 331 阅读 · 0 评论 -
洛谷 P1019 单词接龙 (DFS)
题目描述单词接龙是一个与我们经常玩的成语接龙相类似的游戏,现在我们已知一组单词,且给定一个开头的字母,要求出以这个字母开头的最长的“龙”(每个单词都最多在“龙”中出现两次),在两个单词相连时,其重合部分合为一部分,例如 beastbeast和astonishastonish,如果接成一条龙则变为beastonishbeastonish,另外相邻的两部分不能存在包含关系,例如atat 和 atid...原创 2018-09-25 21:41:31 · 241 阅读 · 0 评论 -
洛谷 P1219 八皇后 【深度搜索 + 回溯】
题目描述 检查一个如下的6 x 6的跳棋棋盘,有六个棋子被放置在棋盘上,使得每行、每列有且只有一个,每条对角线(包括两条主对角线的所有平行线)上至多有一个棋子。 上面的布局可以用序列2 4 6 1 3 5来描述,第i个数字表示在第i行的相应位置有一个棋子,如下:行号 1 2 3 4 5 6列号 2 4 6 1 3 5这只是跳棋放置的一个解。请编一个程序找出所有跳棋放置的解。并把...原创 2018-08-27 15:41:49 · 668 阅读 · 0 评论 -
FatMouse and Cheese [DFS + 记忆化搜索]
FatMouse has stored some cheese in a city. The city can be considered as a square grid of dimension n: each grid location is labelled (p,q) where 0 <= p < n and 0 <= q < n. At each grid lo...原创 2018-08-10 18:02:51 · 114 阅读 · 0 评论 -
滑雪 DFS + 记忆化搜索
Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激。可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你。Michael想知道载一个区域中最长的滑坡。区域由一个二维数组给出。数组的每个数字代表点的高度。下面是一个例子 1 2 3 4 5 16 17 18 19 6 15 24 25 20 7 14 23 22 21 8 13 12...原创 2018-08-10 18:01:22 · 234 阅读 · 0 评论 -
How Many Equations Can You Find
Now give you an string which only contains 0, 1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9.You are asked to add the sign ‘+’ or ’-’ between the characters. Just like give you a string “12345”, you can work out a string ...原创 2018-08-01 20:20:25 · 116 阅读 · 0 评论 -
Oil Deposits
The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with one large rectangular region of land at a time, and creates a grid that divides th...原创 2018-08-01 20:19:37 · 112 阅读 · 0 评论 -
Tempter of the Bone
The doggie found a bone in an ancient maze, which fascinated him a lot. However, when he picked it up, the maze began to shake, and the doggie could feel the ground sinking. He realized that the bone ...原创 2018-08-01 20:18:12 · 115 阅读 · 0 评论 -
Red and Black 【POJ 1979】
题目链接:http://poj.org/problem?id=1979思路:就是一个简单的深度搜索,规定四个方向,遇到 “ . "的时候就可以继续走并且计数。在走过这一步的之后,把这一步的的 " . " 更改为 “#”。#include <stdio.h>#include <string.h>#include <iostream>using name...原创 2018-12-22 23:23:31 · 157 阅读 · 0 评论