1.9 Learning Blog

Backtracking algorithm... It’s a bit difficult to combine the topics...
Topic link: Full permutation
Insert picture description here
This kind of typical permutation, seeking all combinations can use backtracking algorithms, most of which are combined with other methods to solve them.
Ideas:
1. The backtracking algorithm uses DFS depth-first search to find a path all the way to the end;
2. Every time it returns from the last node to the upper level of the decision tree, consider the next node all the way to the end
3. Use on each path To a node will be marked as used, delete the mark before returning to the decision tree of the previous layer,
so that this node can be selected in the previous layer
4, until all the decision trees are completed, the end

Part of the code (drawing from the ideas and codes of the big guys in the problem solution):
Insert picture description here

Insert picture description here
Insert picture description here
I came into contact with the backtracking algorithm today, and I feel that the difficulty is indeed a bit high. I will continue to practice the corresponding questions in the follow-up to master the backtracking method of this topic.

Guess you like

Origin blog.csdn.net/weixin_47529865/article/details/112399648