Ch8.8: 8 queen problem

来源:互联网 发布:小型网络射击游戏 编辑:程序博客网 时间:2024/05/20 08:01

In order to solve this problem efficiently,

need to use backtracking method instead of iterations. Aka: Backtracking is a general algorithm for finding all (or some) solutions to some computational problem, that incrementally builds candidates to the solutions, and abandons each partial candidate c ("backtracks") as soon as it determines that c cannot possibly be completed to a valid solution. 点击打开WIKI链接

Since all the queens can not be in same column, so use array[SIZE] to store instead of a 8x8 matrix. eg: arr[8]={1,2,3,4,5,6,7} means queen are in diagonal.

one solution can be this:



0 0
原创粉丝点击