救救小学生吧
#include<iostream>
using namespace std;
int map[15];
int cnt,n;
void _cout(int num){
if(num <= 3){
for(int i = 1;i <= n;i++){
cout<<map[i]<<" ";
}
cout<<endl;
}
}
bool check(int x,int y){
for(int i = 1;i <= x;i++){
if(map[i] == y)return false;
if(i + map[i] == x + y)return false;
if(i - map[i] == x - y)return false;
}
return true;
}
void dfs(int x){
if(x == n + 1){
cnt++;
_cout(cnt);
return;
}
for(int i = 1;i <= n;i++){
if(check(x,i)){
map[x] = i;
dfs(x + 1);
map[x] = 0;
}
}
}
int main(){
cin>>n;
dfs(1);
cout<<cnt;
}