Can someone pls tell me what is the mistake in my solution ?
The problem is just to solve N-Queens problem for 1<=n<=8;
Question link : TIC04 Problem - CodeChef
Solution link : CodeChef: Practical coding for everyone
Can someone pls tell me what is the mistake in my solution ?
The problem is just to solve N-Queens problem for 1<=n<=8;
Question link : TIC04 Problem - CodeChef
Solution link : CodeChef: Practical coding for everyone
@priyanshi_garg
In function PlacenQUEEN
you need to first check for every place a queen can be placed or not
insted of Placenqueen
use:_
bool solvequeen(int board[d][d],int col)
{
int n=4;
if(col>=n)
return true;
for(int i=0;i<n;i++)
{
if(issafe(board,i,col))
{
board[i][col]=1;
if(solvequeen(board,col+1))
return true;
board[i][col]=0;
}
}
return false;
}
Thanks @sjsahil0844. I am really looking for the mistake in my code.
Can you pls explain that condition where you are checking whether the matrix cell contains queen or not. I think that as we are filling matrix row by row so there was no need to check for it. Am I right ??
yaa
okk