Answered step by step
Verified Expert Solution
Link Copied!

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 #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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Server T-SQL Recipes

Authors: David Dye, Jason Brimhall

4th Edition

1484200616, 9781484200612

More Books

Students also viewed these Databases questions

Question

Provide examples of KPIs in Human Capital Management.

Answered: 1 week ago

Question

What are OLAP Cubes?

Answered: 1 week ago