Don't say much nonsense, first dry.
Https://github.com/NeighborhoodWang/algorithm_NQueens_HorseStep/blob/master/N_queens_puzzle.cpp
Https://github.com/NeighborhoodWang/algorithm_NQueens_HorseStep/blob/master/horse_step.cpp
The following link is I write in C language solution, the shortcomings please correct me.
The question of n Queens is a classic question, the problem is that in an n X N chess plate to visit the n Chess queen, and the N queen can not conflict with each other, the Queen may eat slash, portrait, horizontal pieces.
Friends who don't understand the rules can watch this video:
Http://v.ku6.com/show/rPG951keVUTDvdLn.html
To solve this problem, a relatively basic algorithm "recursion" is used.
is actually a branch of recursion "search".
How to solve the search problem?
Since search is a branch of recursion, it is necessary for the search to have all the attributes contained in the recursion.
1. Initial settings, where to start the search
2. Determine if the simplest situation is reached (when it ends)
3. Computational relationships with other conditions.
The specific implementation steps are as follows:
Search questions:
Determine if the simplest condition is met
The first step: enumerate the possible actions for each feasible action:
Step two: Try this action
Step three: Calculate the next level of search
Fourth step: Undo this action
Fifth step: If the content in the first step is not enumerated, turn to the second step.
Returns the return value.
So what is the relationship between this and the next level in the N-Queens question?
The checkerboard is represented by a Cartesian coordinate system, if there are only eight queens.
The vault problem is similar to the N queen problem, except that there is a chance that the vault will repeat itself in the process, so that the previous steps are repeated, and it is likely that our program will never end.
So you have to use a list to record the skipped coordinates, and then before jumping to determine whether to jump to this point before, if you jump, no longer jump upward.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
N Queen problem and vault problem