ACM summary of the first week of summer camp

Learning content: bfs, dfs, greedy, pruning
Summary:
This is the first week summer training camp, so to summarize life situations. Summer weather is very hot but the air-conditioned classrooms, the cafeteria food was okay, daily training time is very long but also very fulfilling feeling nice short now have become accustomed to summer camp life.
This week training content is search (bfs, dfs) and greedy, training is the way to do problems and self-learning. because before you learned bfs and dfs, so the bfs and dfs also have a certain understanding, so I talk about my own understanding.
both algorithms are violent search algorithm, the search is select the correct answer from all answers generated by the title. and the way these two search is not large, as if all the answers as a picture, then, bfs is the beginning of the expansion from the first node in each direction of its adjacent node, and then turn on the adjacent nodes to expand until you find the correct answers or complete traversal Photo end (indeed very violent). the code is not difficult to achieve, mainly through the queue to achieve, it is to join the first node the queue, and then extend to adjacent nodes turn them into the team, after the first expansion team to finish a team so that it can be extended to the next node, until the queue is empty, ie all nodes extend over or find The correct answer to exit. Bfs because every node once the expansion is the number of steps +1 on a node, so bfs often used to find the shortest path.
And dfs is from the first node to start in only one direction to an adjacent node, after such completion of traversing all nodes (or locate occur node) return to the previous node, then the traversal in the other direction, until complete traversal of all paths. and the code is obtained by a recursive function to implement, and
pay attention to back. I feel many problems can be seized by dfs positive solution, but the time complexity is too high. For example, you find the shortest path, dfs need to find all paths and choose among the shortest, but bfs only need to be extended to the first node to the end. efficiency is completely different Thus the blind use dfs may time out or because of too many layers of recursion take up too much space burst.
while these two algorithms is very violent, but the time complexity can be optimized by pruning, pruning and some have a certain degree of difficulty, flexibility high to currently available is not very good.
Greed is the problem into several sub-problems and select the optimal solution, and finally merged into the general question of optimal solution, provided that the solution to this problem does not affect the child a question that is not Aftereffect. The process is simple but the focus in the end is to see that this problem can not be greedy ...
then write the following topics are some of the ideas .BEJGJKL questions are some simple search through these problems deepened familiarity with the search,
H is an array simulation title list, but the purple book the code is very refined it seems a long time to understand .O title bfs pruning is very important, for example, can not be reduced to a negative number, the current number of steps can not be more than the minimum number of steps recorded, the current can only be used when the number exceeding the target of subtraction, etc. pruning .P question is not the number of remaining colors painted a color which can not exceed (the rest of the grid number +1) / 2, I began to think of all results in a timeout .M question all the time in different states cited again seek the best solution, part somewhat difficult to achieve, C with violent title set is thought to generate the sub dfs .F + dfs problem is greedy, converted into coordinates so as to determine the boundary, and the boundary of sorts, so that the top surface of the upper boundary of the high this use Greedy thoughts, because the above first coloring certainly painted more, then each painted the colors dfs. The remaining four did not finish the problem in large numbers to use A, D processing to the input of a bit of trouble , I is a state diagram of bfs and build optimized pruning (will not), N did not see the problem should be hard, have time on these issues up.
this week the two a game only, there is time to study later at problem solution.
currently downside is difficult search problem can not make fully, consider pruning is not in place, to be improved.

Guess you like

Origin www.cnblogs.com/megadeth/p/11297199.html