xuhrrr @ 2023-10-29 21:18:33
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
int n;
long long ans = 0;
int col[25],zx[30],yx[30];
int a[20];
void dfs(int x){ // x means which qz is put
if(x > n){
ans++;
if(ans <= 3){
for(int i = 1; i <= n ; ++i){
cout << a[i] <<" ";
}
cout << endl;
}
return;
}
for(int i = 1 ; i <= n ; ++i){
if(col[i] == 0 && zx[abs(i + x)] == 0 && yx[abs(i - x)] == 0){
a[x] = i;
col[i] = 1; zx[abs(i + x)] = 1; yx[abs(i - x)] = 1;
dfs(x + 1);
col[i] = 0; zx[abs(i - x)] = 0 ; yx[abs(i - x)] = 0;
}
}
}
int main()
{
memset(col,0,sizeof(col));
memset(zx,0,sizeof(zx));
memset(yx,0,sizeof(yx));
cin >> n;
dfs(1);
cout << ans << endl;
return 0;
}