DFS
biongbiongdou
这个作者很懒,什么都没留下…
展开
-
DFS——N个皇后
最近在自学DFS,N个皇后是一个DFS的经典应用,主要思想是递归。学习时,我参考了:https://blog.csdn.net/coding_or_dead/article/details/52487854注释中加入了一些自己的理解代码:#include <stdio.h>#include<cstdlib>using namespace std;int map[12]...原创 2018-04-08 21:55:27 · 154 阅读 · 0 评论 -
【POJ】1979 Black and Red(DFS)
Red and BlackTime Limit: 1000MS Memory Limit: 30000KTotal Submissions: 41057 Accepted: 22269DescriptionThere is a rectangular room, covered with square tiles. Each tile is colored either red or black....原创 2018-04-19 22:05:16 · 144 阅读 · 0 评论 -
【HDU】1728 逃离迷宫(C++/C)
Problem Description 给定一个m × n (m行, n列)的迷宫,迷宫中有两个位置,gloria想从迷宫的一个位置走到另外一个位置,当然迷宫中有些地方是空地,gloria可以穿越,有些地方是障碍,她必须绕行,从迷宫的一个位置,只能走到与它相邻的4个位置中,当然在行走过程中,gloria不能走到迷宫外面去。令人头痛的是,gloria是个没什么方向感的人,因此,她在行走过程中,不能...原创 2018-05-17 14:42:44 · 1527 阅读 · 0 评论 -
【HDU】2514 Another Eight Puzzle(C++/C)
Problem DescriptionFill the following 8 circles with digits 1~8,with each number exactly once . Conntcted circles cannot be filled with two consecutive numbers.There are 17 pairs of connected cicles:A...原创 2018-05-17 16:28:10 · 179 阅读 · 0 评论 -
【HDU】2209 翻纸牌游戏(C/C++)
Problem Description有一种纸牌游戏,很有意思,给你N张纸牌,一字排开,纸牌有正反两面,开始的纸牌可能是一种乱的状态(有些朝正,有些朝反),现在你需要整理这些纸牌。但是麻烦的是,每当你翻一张纸牌(由正翻到反,或者有反翻到正)时,他左右两张纸牌(最左边和最右边的纸牌,只会影响附近一张)也必须跟着翻动,现在给你一个乱的状态,问你能否把他们整理好,使得每张纸牌都正面朝上,如果可以,最少需...原创 2018-05-17 20:46:10 · 2535 阅读 · 0 评论 -
【LeetCode】695. Max Area of Island
题目:Given a non-empty 2D array grid of 0's and 1's, an island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are sur...原创 2018-05-11 16:38:28 · 129 阅读 · 0 评论 -
【HDU】2614 Beat(C++/C)
Problem DescriptionZty is a man that always full of enthusiasm. He wants to solve every kind of difficulty ACM problem in the world. And he has a habit that he does not like to solvea problem that is ...原创 2018-05-19 12:13:02 · 235 阅读 · 0 评论 -
【LeetCode】690 Employee Importance(C++)
You are given a data structure of employee information, which includes the employee's unique id, his importance value and his directsubordinates' id.For example, employee 1 is the leader of employee 2...原创 2018-05-14 20:23:30 · 203 阅读 · 0 评论 -
【LeetCode】100. Same Tree
Given two binary trees, write a function to check if they are the same or not.Two binary trees are considered the same if they are structurally identical and the nodes have the same value.Example 1:In...原创 2018-05-14 20:47:43 · 131 阅读 · 0 评论 -
【LeetCode】733. Flood Fill (C++)
An image is represented by a 2-D array of integers, each integer representing the pixel value of the image (from 0 to 65535).Given a coordinate (sr, sc) representing the starting pixel (row and column...原创 2018-05-14 21:19:17 · 530 阅读 · 0 评论 -
【LeetCode】108. Convert Sorted Array to Binary Search Tree(C++)
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the t...原创 2018-05-14 22:11:06 · 223 阅读 · 0 评论 -
【HDU】1269 迷宫城堡(C++)
Problem Description为了训练小希的方向感,Gardon建立了一座大城堡,里面有N个房间(N<=10000)和M条通道(M<=100000),每个通道都是单向的,就是说若称某通道连通了A房间和B房间,只说明可以通过这个通道由A房间到达B房间,但并不说明通过它可以由B房间到达A房间。Gardon需要请你写个程序确认一下是否任意两个房间都是相互连通的,即:对于任意的i和j,...原创 2018-05-16 20:29:29 · 903 阅读 · 0 评论 -
【POJ】1321(DFS——棋盘问题)
棋盘问题Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 59850 Accepted: 28687Description在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别。要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有可行的摆放方案C。Input输...原创 2018-04-19 22:00:56 · 115 阅读 · 0 评论 -
DFS——拯救OIBH总部
拯救OIBH总部(来源于http://acm.qust.edu.cn/problem.php?id=1101)OIBH被突来的洪水淹没了> .< 还好OIBH总部有在某些重要的地方起一些围墙,用*号表示,而一个封闭的*号区域洪水是进不去的……现在给出OIBH的围墙建设图,问OIBH总部没被淹到的重要区域(由" 0" 表示)有多少。输入第一行是两个数,x和y(x,y< =500) ...原创 2018-04-19 18:57:33 · 755 阅读 · 0 评论 -
DFS——求1—N所有数字的全排列
代码://// main.cpp// DFS——全排列//// Created by showlo on 2018/4/14.// Copyright © 2018年 showlo. All rights reserved.//输出从1到N的全排列#include <stdio.h>#include <algorithm>#include <...原创 2018-04-14 22:08:49 · 927 阅读 · 0 评论 -
DFS——八个皇后—N个皇后的总结
1.八个皇后(指定n=8),输出所有可能摆放的个数代码://// main.cpp// DFS——八个皇后自己写//// Created by showlo on 2018/4/14.// Copyright © 2018年 showlo. All rights reserved.//#include <stdio.h>#include <math.h&...原创 2018-04-14 22:12:27 · 213 阅读 · 0 评论 -
DFS——几个数字的和=目标
Description:现给定一个含有n个元素的数组A,要求:从这n个数中选择一些数,这些数的和恰好为kInput:多组测试数据。第一行为n(1<=n<=20) 第二行为n个整数,每个数的范围为(-10^8≤A[i]≤10^8) 第三行为整数k(-10^8≤k≤10^8).Output:如果能够达到目的,输出”Of course,I can!”; 否则输出”Sorry,I can’t!...原创 2018-04-09 20:59:30 · 556 阅读 · 1 评论 -
【HDU】DFS——N个数中k个数成绩的和
这篇主要参考了:https://blog.csdn.net/Coding_Or_Dead/article/details/52326519感觉DFS真正应用起来还是有点困难描述:问题很简单,给你Ñ个正整数,求出这Ñ个正整数中所有任选ķ个相乘后的和。 输入:输入有两行,第一行是两个整数Ñ和K,其中1 <= K <= N <= 10。接下去一行就是Ñ个正整数,保证最后结果用长即可保存...原创 2018-04-09 21:21:33 · 545 阅读 · 0 评论 -
【HDU】1016 DFS——Prime Ring Problem
Problem DescriptionA ring is compose of n circles as shown in diagram. Put natural number 1, 2, ..., n into each circle separately, and the sum of numbers in two adjacent circles should be a prime.Not...原创 2018-04-15 16:14:57 · 140 阅读 · 0 评论 -
【POJ】1562 Oil Deposits(DFS)
DescriptionThe 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...原创 2018-04-16 10:44:34 · 143 阅读 · 0 评论 -
DFS——细胞问题
题目:1009: 细胞Description一矩形阵列由数字0到9组成,数字1到9代表细胞。细胞的定义为沿细胞数字上下左右还是细胞数字则为同一细胞。求给定矩形阵列的细胞个数。如阵列 4 100234500067103456050020456006710000000089有4个细胞。Input第一行包含2个整数n和m,分别表示矩形阵列的行数和列数。接下来的n行,每行m个数字,代表细胞的矩形阵列。...原创 2018-04-16 11:46:53 · 1774 阅读 · 0 评论 -
【HDU】1016 Prime Ring Problem(DFS)
Problem DescriptionA ring is compose of n circles as shown in diagram. Put natural number 1, 2, ..., n into each circle separately, and the sum of numbers in two adjacent circles should be a prime.Not...原创 2018-04-12 09:10:09 · 106 阅读 · 0 评论 -
DFS-六角填数
下图所示六角形中,填入1~12的数字。使得每条直线上的数字之和都相同。图中,已经替你填好了3个数字,请你计算星号位置所代表的数字是多少?这道题用DFS遍历来解决,感觉递归是一个蛮神奇的东西,可能还是理解不深,希望以后能通过多做一些题,更深地理解DFS算法的核心——递归。代码://// main.cpp// DFS-六角填数//// Created by showlo on 2018/...原创 2018-04-05 22:52:07 · 299 阅读 · 0 评论 -
【HDU】1010 Tempter of the Bone
Problem DescriptionThe 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 real...原创 2018-04-13 21:17:52 · 92 阅读 · 0 评论 -
DFS——迷宫问题(输出搜索过程及路径长度)
题目与上一篇BFS是一样的,这里用DFS实现是为了探究二者遍历的区别。DFS代码://// main.cpp// DFS(迷宫问题自己写)可输出搜索过程//// Created by showlo on 2018/4/14.// Copyright © 2018年 showlo. All rights reserved.//#include <stdio.h>...原创 2018-04-14 10:46:35 · 1530 阅读 · 0 评论 -
【ZOJ 1003】 Crashing Balloon(DFS)
好久没有更新过了,一直看paper,看算法,这几天重新开始刷题大业,发现果然生疏了(捂脸哭PS:发现CSDN变化好大,写博客、编辑文章更人性化了。。。下面切入正题这次找了一道简单的ACM模拟题,涉及数论和dfs递归。参考:https://blog.csdn.net/axiqia/article/details/51096709 /*描述:六一儿童节,小朋友们做踩气球游戏,...原创 2018-07-29 14:52:54 · 484 阅读 · 0 评论