42 lines
841 B
C
42 lines
841 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
int ans, a[10005];
|
|
int n;
|
|
int cx[100], zx[100], col[100];
|
|
|
|
void dfs(int x) {
|
|
if (x > n) {
|
|
ans++;
|
|
if (ans <= 3) {
|
|
for (int i = 1; i <= n; i++) {
|
|
printf("%d ", a[i]);
|
|
}
|
|
printf("\n");
|
|
}
|
|
return;
|
|
}
|
|
for (int i = 1; i <= n; i++) {
|
|
int l = x + i, r = x - i + 15;
|
|
if (cx[r] == 0 && zx[l] == 0 && col[i] == 0) {
|
|
a[x] = i;
|
|
cx[r] = 1;
|
|
zx[l] = 1;
|
|
col[i] = 1;
|
|
dfs(x + 1);
|
|
cx[r] = 0;
|
|
zx[l] = 0;
|
|
col[i] = 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
int main() {
|
|
scanf("%d", &n);
|
|
dfs(1);
|
|
printf("%d", ans);
|
|
return 0;
|
|
}
|
|
|
|
// Ref: P1219 [USACO1.5] 八皇后 Checker Challenge
|
|
// https://www.luogu.com.cn/record/40132197
|