Use STL to implement DFS/BFS Algorithms
-- Check the duplicate statusA few days ago, some netizens commented that my use of "Shen" and "Shen Kuan" is a second-class word. The correct statement should be "depth first" and "breadth first ". Although attitudes and words are a bit unacceptable, the comments are a bit reasonable. To be honest, I do not remember where I learned the first word "Shen" and "Shen Kuan", but I can be certain that I cannot create
Label: ACM algorithm DP Algorithm
Poj 1252 euro efficiency (BFS or full backpack)
Http://poj.org/problem? Id = 1252
Question:
There are 6 currencies in which their nominal values are 1, V2, V3, V4, V5, and v6, and their maximum values are less than 100. the minimum value is always 1 (that is, V1 ). the problem now is that you need to use up the six currencies in a small amount.StructureThe amount of money with a nominal value of 1 to 100. How
DescriptionProblem B-BFS (Binary Fibonacci string)
We are familiar with the Fibonacci sequence (1, 1, 2, 3, 5, 8,...). What if we define a similar sequence for strings? Sounds interesting? Let's see.
We define the follwing sequence:
BFS (0) = 0BFS (1) = 1 (here "0" and "1" are strings, not simply the numerical digit, 0 or 1)
For All (n> 1)BFS (n) =
can let them meet.Sample Input4 4y.#@.....#. @.. M4 4y.#@.....#. @#. M5 5[email protected].#....#...@. m.#...#Sample Output668866AuthoryifenfeiThe age of Source struggleRecommendyifenfei Test instructions: Y and M two people agreed to meet at @, ask two people add up the shortest time is how much analysis: BFS does not need to each @ BFS, with Y and M as the starting point for
Hdu 4230 bfs + memory-based search
The number of steps from the start point to the end point;
Mark indicates the minimum number of steps corresponding to each vertex in each direction;
Num indicates planting trees;
Search for the question.
#include
#include
#include
#include
using namespace std
;#define INF 0x3f3f3f3f
struct node
{ int x
,y
,step
; int d
;}a
,b
;int n
In the basic algorithm of graph, the first need to contact is the graph traversal algorithm, according to the order of access nodes, can be divided into depth-first search (DFS)和Breadth First Search (BFS)。 DFS (deep first search) algorithmDepth-first-searchDepth-first algorithm is an algorithm for traversing or searching a tree or graph. Traverse the tree's nodes along the depth of the tree, searching the branches of the tree as deep as possible.When
[Cpp] // question: the diameter of the tree // thought: // the diameter of the tree refers to the longest simple path of the tree. Method: Twice BFS: first select a starting point BFS to find the longest path end point, and then perform BFS from the end point, then the longest path found by BFS is the diameter of the t
PackageMyalgorithm;Importjava.util.Arrays;Importjava.util.LinkedList;ImportJava.util.Queue;/*The structure of the location and value of the BFS used for recording*/classnode{Node (intXparamintYparam,intValparam) { This. x =Xparam; This. y =Yparam; This. Value =Valparam; } intX,y,value;} Public classShortPath {/*Global Shortest Path*/ Public intStepnum = 999; /*build the maze of 11*11, Hero H in the location of (the), to save beauty m
"Dfs/bfs+set+ fast Power" Swjtuoj 2094"Note: Jiaotong University to see this article to learn to write their own, do not play for the game!" ~Main topicQuestion one: The protagonist goes on vacation, ask after a^b days is the day of the week (simple question)Question two: a balance, n weights, the weight of each object WI is known, ask how many of the weight can be weighed?The second thing to note is that the weights can be placed on both sides of the
[LeetCode from zero to single row] No133. clon graph (BFS breadth-first search), leetcodebfsBackground (the following background information reproduced from: http://www.cnblogs.com/springfor/p/3874591.html? Utm_source = tuicool)
DFS (Dpeth-first Search)As its name implies, it is a deep search, where one path goes to the dark and another path is selected.I remember when I went to Algorithm, the professor gave an example, that is, DFS is like a curious
Hdoj 1242 Rescue (BFS)
Rescue
Http://acm.hdu.edu.cn/showproblem.php? Pid = 1, 1242
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission (s): 18962 Accepted Submission (s): 6771
Problem Description Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The prison is described as a N * M (N, M
Angel's friends want to save Angel. their task is: approach Angel. we assume that "approach Angel" is t
[2], 2, 3, 1, 0
LEFT SearchDirection [3], 3, 0, 1, 2
It is easy to determine the search direction and Search Start Point Based on the initial direction, but how can we determine the next direction after the search.
If selected, SearchDirection [0]-> corresponds to the last LEFT
SearchDirection [1]-> UP
SearchDirection [2]-> RIGHT
SearchDirection [3]-> DOWN
Assume that the initial direction is d represented by enum {UP, RIGHT, DOWN, LEFT}, and the selected searchction ction is I, then the final
Breadth-First traversalBreadth-first traversal is a graph traversal method that is often seen and common, with the exception of BFS and DFS, which is the depth-first traversal method. I'll write it in my next blog post.Traversal processI believe every person who looks at this blog will be able to read and understand the adjacency list storage diagram.Do not understand the people. Please learn the storage method first. In my previous blog.Portal: Diagr
A classic BFS example to illustrate the concept of BFS
Zoj2913-bus Pass Test instructions: Find a center area, so that center to all bus lines shortest, equidistant center is the output ID of the smallest. The main point: the classic BFS, by the bus line at most only through the 10*20 zone, and the total area of up to 10^5, so should be from the bus line t
Given a 2D board containing ‘X‘ ‘O‘ and, capture all regions surrounded by ‘X‘ .A region was captured by flipping all ‘O‘ s into ‘X‘ s-surrounded region.For example,x x x xx o o xx x o xx o x xAfter running your function, the board should is:x x x xx x x xx x x xx O x xThe problem: The test data card is very strict. Started with the DFS burst stack, and later changed to BFS and timed out. Finally improved the next: Check the edge of There is no ' O ',
If this problem can constitute the area of non-interference, its composition of the figure is actually Hamilton Road, So if can be observed directly into the existence of Hamilton Road proof, even if not observed, I believe that Acmer can also be converted into BFS problem, this problem is a good graph theory, it is helpful to examine the basic skills of their own graph theory.
Wireless broadcast (broadcast)
DescriptionA broadcasting compa
0Checkerboard problem, change the color of a child, the child and the child around the four positions (left and right) of the child to change color, to find the minimum number of changes.Most of this type of problem should be solved with state compression + brute force search. It's not quite reasonable to find the rules purely.1) The first method, state compression after the BFS violent search. Because the chessboard is small, there are only 16 square
Topic Links:Lightoj 1174-commandosTitle Description:There is an army adhering to do the best slogan, ready to destroy the enemy barracks. They plan to put a bomb in every enemy barracks. There are plenty of soldiers in the barracks, every soldier can carry enough bombs, ask the army to complete the task at least time? (If the soldiers were to put bombs in the enemy tent, the enemy would not defend them.) is the enemy a pig? Is this a fight with a pig? )Problem Solving Ideas:Water problem, the
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.