Number the board locations 0..n^3-1. Write a function
bool search(int startingLocation, int queensToPlace) If queensToPlace is zero, this is your base case. Output the board and you are done. The function loops over the locations from the startingLocation to the end of the board. If each location is a legal spot to place a queen, put one there and call search recursively starting at your current location+1, placing one fewer queens. Remove the queen from that location and move on to the next. I didn't say much about how to determine is a move is legal. The brute force method of scanning every line for another queen is complicated and slow. A better way is to maintain a mapping from each board location to the rows it belongs to. In a 3D board a location might belong to as many as 13 rows. For each row, keep a count of how many queens are in that row. A move is not legal if any of the rows already contain a queen. When you place a queen you must update (increment) all of the rows for that location, and when you remove it, you must decrement the counts. Don On Apr 27, 3:08 am, ARM1610 <ashishrmod...@gmail.com> wrote: > Hello all, > I'm not getting how to solve a 3 d version of n queen problem. The > specification are A n*n*n board is given, arrange n*n queens such that not a > single queen crosses(kills) any other queen. Use back tracking or divide and > conquer. > > All solutions / suggestions are welcome !! > Thanking You in advance !! > > Regards > Ashish > VIT Pune -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.