标签:
Description
Input
Output
Sample Input
Sample Output
#include"iostream"
#include"cstring"
using namespace std;
int n;
int temp;
int a[11];
void DFS(int step)
{
if(step==n+1)
{
temp++;
return;
}
int flag;
for(int i=1;i<=n;i++)
{
a[step]=i;
flag=0;
for(int j=1;j<step;j++)
{
if(a[j]==i||i-step==a[j]-j||i+step==a[j]+j)
{
flag=1;
break;
}
}
if(flag==0) {DFS(step+1);}
}
}
int main()
{
int ans[11];
for(n=1;n<=10;n++)
{
temp=0;
memset(a,0,sizeof(a));
DFS(1);
ans[n]=temp;
}
int m;
while(cin>>m&&m)
cout<<ans[m]<<endl;
return 0;
}
标签:
原文地址:http://www.cnblogs.com/zsyacm666666/p/4664793.html