Thursday, July 9, 2009

Solve N queens problem and display each solution in some graphical user interface.(using C program)?

a classic combinatorial problem is to place N queens on an N*N chessboard so that no two"attack",that is so that no two of them are on the same row,column or diogonal.The case study gives a graphical user interface simulation for this N queens problem.It will read the value N first then display each and every solution for this N queens problem in N*N chessboard.

Solve N queens problem and display each solution in some graphical user interface.(using C program)?
I wont be able to show the coding to you. But I could give you the algorithms. All you have to do is use the brute force algorithms which checks for all probability. This algorithms are really useful IF the n-value is small.


For bigger n-value, you'll have to use Dynamic Programming a.k.a DP algorithms.





Here's the quick look:


First, put the queen in 1,1 then put "false" in 1,2 to 1,N and 2,1 until 2,N and 2,2 until N,N.


Then put the next queen in 1,2. Since it has been labeled "false", the queen cant be put here.


Then move to next block, 1,3. Since it has been labeled "false" too. It is impossible for the queen to be placed here.


Then move until 3,2 where there is no "false" label, put the queen there and start the "label" process again.


Loop this until all the board has been labeled "false".





Got it?





Have fun!





peace


vixklen
Reply:PLEASE XPLAIN ME THE QUESTION
Reply:N queen problem is an NP hard problem, means there is no shortcut. You should consider all the solutions. The second method in above solution is the only solution.


No comments:

Post a Comment