In the count n-queen problem i am getting wrong answer after n>8

the code which i used is here

using namespace std;
int ld[12] = {0};
int rd[12] = {0},
vertical[12] = {0};

bool isPossible(int i, int j, int n)
{
if(rd[i+j]==1)
{
return false;
}
else if(ld[i-j+n-1] == 1)
{
return false;
}
else if(vertical[j]==1)
{
return false;
}
return true;
}

bool count(int index, int size, int &c)
{
if(index==size)
{
c++;
return false;
}
for(int i = 0;i<size;i++)
{
if(isPossible(index,i,size))
{
ld[index-i+size-1] = 1;
rd[index+i] = 1;
vertical[i] = 1;
if(count(index+1,size,c))
{
return true;
}
ld[index-i+size-1] = 0;
rd[index+i] = 0;
vertical[i] = 0;
}
}
return false;
}

int main() {
int c = 0;
int n = 0;
cin>>n;
if(!count(0,n,c))
{
cout<<c;
}
else
{
cout<<"";
}
return 0;
}

@YatharthVardan
Please send your code on CB IDE
Biggest test case has size of 13
So look into that as well

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

The coding blocks ide code no. is

your approach to this problem is wrong
Understand the approach and try again

Nqueen problem Approach

The idea is to place queens one by one in different columns, starting from the leftmost column. When we place a queen in a column, we check for clashes with already placed queens. In the current column, if we find a row for which there is no clash, we mark this row and column as part of the solution. If we do not find such a row due to clashes then we backtrack and return false.

  1. Start in the leftmost column
  2. If all queens are placed
    return true
  3. Try all rows in the current column.
    Do following for every tried row.
    a) If the queen can be placed safely in this row
    then mark this [row, column] as part of the
    solution and recursively check if placing
    queen here leads to a solution.
    b) If placing the queen in [row, column] leads to
    a solution then return true.
    c) If placing queen doesn’t lead to a solution then
    unmark this [row, column] (Backtrack) and go to
    step (a) to try other rows.
  4. If all rows have been tried and nothing worked,
    return false to trigger backtracking.

your is possible function is also wrong
correct one is

/// col check
for(int x=0;x<i;x++){
if(board[x][j]==1)return false;
}
// left daigonal check
int x=i,y=j;
while(x>=0&&y>=0){
if(board[x][y]==1)return false;
x–;y–;
}

//right daigonal check
x=i,y=j;
while(x>=0&&y<n){
	if(board[x][y]==1)return false;
	x--;y++;
}
return true;

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.