#include<cstdio>
#include<cstdlib>
using namespace std;
bool a[9]; //行数
bool b[15];//行-列
bool c[17];//行+列
int sum=0;
void f(int i)//i代表行数
{
if(i>8)
{
++sum;//记次数
return;
}
else
for(int j=1;j<=8;j++)//j代表列数
{
if(a[j]&&b[i-j+7]&&c[i+j])
{
a[j]=b[i-j+7]=c[i+j]=false;
f(i+1);
a[j]=b[i-j+7]=c[i+j]=true;
}
}
}
int main()
{
for(int i=1;i<=8;i++)a[i]=true;
for(int i=0;i<=14;i++)b[i]=true;
for(int i=2;i<=16;i++)c[i]=true;
f(1);
printf("%d\n",sum);
system("pause");
return 0;
}
#include<cstdlib>
using namespace std;
bool a[9]; //行数
bool b[15];//行-列
bool c[17];//行+列
int sum=0;
void f(int i)//i代表行数
{
if(i>8)
{
++sum;//记次数
return;
}
else
for(int j=1;j<=8;j++)//j代表列数
{
if(a[j]&&b[i-j+7]&&c[i+j])
{
a[j]=b[i-j+7]=c[i+j]=false;
f(i+1);
a[j]=b[i-j+7]=c[i+j]=true;
}
}
}
int main()
{
for(int i=1;i<=8;i++)a[i]=true;
for(int i=0;i<=14;i++)b[i]=true;
for(int i=2;i<=16;i++)c[i]=true;
f(1);
printf("%d\n",sum);
system("pause");
return 0;
}