#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int N = 20;
struct node{
int x,y;
}nn[N];
int n,ans;
bool check(int x, int y){
for(int i=1;i<x;i++){
if(nn[i].y == y || abs(nn[i].x - x) == abs(nn[i].y - y)){
return false;
}
}
return true;
}
void dfs(int step){
if(step == n+1){
ans++;
return ;
}
for(int i=1;i<=n;i++){
if(check(step, i)){
nn[step].x = step;
nn[step].y = i;
dfs(step+1);
}
}
}
int main(){
cin>>n;
dfs(1);
cout<<ans;
return 0;
}
用结构体数组保存已经存好的坐标,对于每行(step)都查一下每列的元素,并check()一下,check函数的作用就是检查是否和原来已有的前面的行的坐标违反了不在同一列,不在同一对角线的规则