Backtracking method to solve the N c + + source co
2016-08-23
0 0 0
no vote
Other
Earn points
#include
#include
#include
#include
using namespace std;
class Queen
{
friend int nQueen (int);
private:
bool Place (int k);
void Backtrack (int t);
void Output ();
int n, // number Queens
* x; // current solution
long sum; // current number of feasible options that have been found
};
bool Queen :: Place (int k)
{
for (int j = 1; j <k; j ++)
{
if ((abs (kj) == abs (x [k] -x [j])) || (x [j] == x [k]))
{
return false;
}
}
return true;
}
void Queen :: Backtrack (int t)
{
if (t> n)
{
sum ++;
Output ();
}
else
{
for (int i = 1; i <= n; i ++)
{
&n
#include
#include
#include
using namespace std;
class Queen
{
friend int nQueen (int);
private:
bool Place (int k);
void Backtrack (int t);
void Output ();
int n, // number Queens
* x; // current solution
long sum; // current number of feasible options that have been found
};
bool Queen :: Place (int k)
{
for (int j = 1; j <k; j ++)
{
if ((abs (kj) == abs (x [k] -x [j])) || (x [j] == x [k]))
{
return false;
}
}
return true;
}
void Queen :: Backtrack (int t)
{
if (t> n)
{
sum ++;
Output ();
}
else
{
for (int i = 1; i <= n; i ++)
{
&n
c++
Related Source Codes
Local Path Planning Algorithm - DWA Algorithm
0
0
no vote
enDAQ-Shock-Data-Share-SRS-Blog
0
0
no vote
Calling chatGPT in a Windows application
0
0
no vote
Test Hello world
0
0
no vote
RCS calculation by one-way ray tracing
0
0
no vote
No comment