I solved the N- Queen problem with the condition that there can only be one queen per column. So I place a queen in a square in first column, then move onto the next column and place a queen in a square not attacked by the queen on board. I am able to find all solutions with this approach but it starts taking a long time after n=13. Also I found that most of the solutions of the problem can be found by rotations and reflections of a very few distinct solutions.E.g 8 queen problem has 92 total solutions out of which only 12 are distinct. (http://en.wikipedia.org/wiki/Eight_queens_puzzle)
So my question is how do I check for these states of the board and only push those states onto the stack which give a distinct solution?
This is what I am doing right now.
typedef struct state{
int board[N][N];
int col;
}state;
state cur;
state next;
stack<state> myS;
myS.push(emptyBoard);
while(!myS.empty()){
cur=myS.top(); myS.pop();
if(cur.col==n){
count++;
continue;
}
for(i=0;i<n;i++){
next=cur;
if(cur.board[i][cur.col]==available){
next.board[i][cur.col]=occupied;
markConflicts(i,cur.col); //mark squares attacked by queen as conflicted
next.col=cur.col+1;
myS.push(next);
}
}
}