#include <bits/stdc++.h>
using namespace std;
int n, a[15][15], cnt;
bool check(int x, int y)
{
for (int i = 1; i <= n; i++)
{
if ((a[x][i] && i != y) || (a[i][y] && i != x)) return false;
if (y - x + 1 <= 0 || x + y - 1 > n)
{
if (a[i][y - x + i] || a[i][x + y - i]) return false;
}
}
return true;
}
void dfs(int m)
{
if (m == n)
{
cnt++;
if (cnt <= 3)
{
for (int i = 1; i <= n; i++)for (int j = 1; j <= n; j++)if (a[i][j]) cout << j << " ";
cout << endl;
}
}
else
{
for (int i = 1; i <= n; i++)
{
if (check(m, i))
{
a[m][i] = 1;
dfs(m + 1);
a[m][i] = 0;
}
}
}
return;
}
int main()
{
cin >> n;
dfs(1);
cout << cnt << endl;
return 0;
}
大家快来调教我