Description:
Accept:
#include<bits/stdc++.h>
using namespace std;
int n, cnt[15][15], ans = 0;
void add(int x, int y) {
//右下
for (int i = x + 1, j = y + 1; i <= n&&j<=n; i++, j++) {
cnt[i][j]++;
}
//左下
for (int i = x + 1, j = y - 1; i <= n && j >= 1; i++, j--) {
cnt[i][j]++;
}
//down
for (int i = x + 1; i <= n; i++) {
cnt[i][y]++;
}
}
void Minus(int x, int y) {
//右下
for (int i = x + 1, j = y + 1; i <= n && j <= n; i++, j++) {
cnt[i][j]--;
}
//左下
for (int i = x + 1, j = y - 1; i <= n && j >= 1; i++, j--) {
cnt[i][j]--;
}
//down
for (int i = x + 1; i <= n; i++) {
cnt[i][y]--;
}
}
void dfs(int now) {
if (now == n + 1) {
ans++;
return;
}
for (int j = 1; j <= n; j++) {
if (cnt[now][j]) {
continue;
}
cnt[now][j]++;
add(now, j);
dfs(now + 1);
cnt[now][j]--;
Minus(now, j);
}
}
int main()
{
while (cin >> n) {
memset(cnt, 0, sizeof(cnt));
dfs(1);
cout << ans << endl;
ans = 0;
}
return 0;
}