#include <iostream>
#include<stdio.h>
#include<vector>
#include<string.h>
#include<math.h>
using namespace std;
const int maxn = 11;
int n;
vector<int> path;
int vis[maxn];
int ci = 0;
void solution(int index)
{
if(index == n + 1)
{
int flag = 1;
for(int i = 0;i<=n;i++)
{
for(int j = i + 1;j<=n;j++)
{
if(fabs(i-j) == fabs(path[i-1]-path[j-1]))
{
flag = 0;
}
}
}
if(flag) ci++;
return ;
}
for(int x = 1;x<=n;x++)
{
if(vis[x] == 0)
{
path.push_back(x);
vis[x] = 1;
solution(index + 1);
path.pop_back();
vis[x] = 0;
}
}
}
int main()
{
scanf("%d",&n);
memset(vis,0,sizeof(vis));
solution(1);
printf("%d\n",ci);
return 0;
}
/*
8
92
*/
2013-2
最新推荐文章于 2023-05-09 10:43:20 发布