Problem 9.9
Write an algorithm to print all ways of arranging eight queens on a chess board so that none of them share the same row, column or diagonal.
- What's the output looks like. (each valid placement is a array, results may put in an vector<int[]>)
- recursion:
- base case: all row are successfully placed, either print results or count ways.
- otherwise check validity to place queens for the followings rows until complete.
- To check the column validity: look all the row we placed already, check whether it is possible to place next row in the intended column(as a parameter to the CheckValidity()).
- To check the diagonal validity: make sure the column distance and row distance is different.
- Might simple to store the results in a two dimension array.
Here is the source code example from CC150 Answer rewrite in C++