S
sahu
N-Queens :
You are given a N x N chessboard & you are required to place N queens
on it so that they can't attack each-other. You just need to find out
the valid positions of the queens and the total number of such valid
combinations. A sample I/p and o/p is given below (where N will be
input by the user).
Sample I/p :
Enter the no. of queens: 4
Sample o/p:
1,3,0,2
2,0,3,1
Total no. of possible combinations = 2
Explanation: In the aforesaid example 4 is the value of N input by the
user(4 x 4 chessboard & 4 queens). The o/p prints the position no.s of
the four queens on the chessboard on screen (position no.s can have
value from 0 to N-1, refer the figure below).
0 1 2 3
- Q - -
- - - Q
Q - - -
- - Q -
The second line shows next such valid combination. Finally it prints
the total no. of such valid combinations on screen.
You are given a N x N chessboard & you are required to place N queens
on it so that they can't attack each-other. You just need to find out
the valid positions of the queens and the total number of such valid
combinations. A sample I/p and o/p is given below (where N will be
input by the user).
Sample I/p :
Enter the no. of queens: 4
Sample o/p:
1,3,0,2
2,0,3,1
Total no. of possible combinations = 2
Explanation: In the aforesaid example 4 is the value of N input by the
user(4 x 4 chessboard & 4 queens). The o/p prints the position no.s of
the four queens on the chessboard on screen (position no.s can have
value from 0 to N-1, refer the figure below).
0 1 2 3
- Q - -
- - - Q
Q - - -
- - Q -
The second line shows next such valid combination. Finally it prints
the total no. of such valid combinations on screen.