Question: fix the error below,and output should be There are 1 solutions to the 1 queens problem. There are 0 solutions to the 2 queens problem.

fix the error below,and output should be

There are 1 solutions to the 1 queens problem. There are 0 solutions to the 2 queens problem. There are 0 solutions to the 3 queens problem. There are 2 solutions to the 4 queens problem. There are 10 solutions to the 5 queens problem. There are 4 solutions to the 6 queens problem. There are 40 solutions to the 7 queens problem. There are 92 solutions to the 8 queens problem. There are 352 solutions to the 9 queens problem. There are 724 solutions to the 10 queens problem. There are 2680 solutions to the 11 queens problem. There are 14200 solutions to the 12 queens problem.

#include #include using namespace std; bool ok (int q[], int c) { for (int i=0; i

int nqueens(int n) { int* q=new int[n]; q[0] =0; int r=0, c=0, solutions=0; while(c>=0) c++; if(c>n) { solutions++; c--; r=q[c]; } else r=-1; while(c>=0) { r++; q[c]=r; if(r>n) { c--; r=q[c]; } else if(ok (q,c)){ break; } } } delete[] q; return solutions; } int main(){ int n=12; for( int i =0; i

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!