Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started