Thinking back

Backtracking

Backtracking (back) part of DFS.

  • DFS is mainly used in common accessibility issues , this problem only need to perform to a specific location and then return to.
  • Backtracking is mainly for solving the permutation problem in combination , for example, { 'a', 'b' , 'c'} three characters, all characters obtained by solving the three characters are arranged in such a problem return execution to a specific position after the implementation of the solution process will continue.

Because Backtracking is not returned immediately, but to continue to solve, so when the program implementation, need to pay attention to the elements of the question mark:

  • When accessing a new element into the new recursive call needs to be a new element marked as having been visited, so as to not repeat visits to the elements while continuing recursive call.
  • But when a recursive return, need not be marked as elements of access, because only ensure a recursive chain does not access an element at the same time, access to already visited but not recursive elements in the current chain.

Guess you like

Origin www.cnblogs.com/yjxyy/p/11111011.html