N Queen's Problem and vault problem

Source: Internet
Author: User

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

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.