#include <cstdio>
#include <ctime>
const int N = 40;
int cnt, n;
bool visc[N], visl[N], visr[N];
void search(int cur) {
if (cur == n) {
cnt++;
return ;
}
for (int i = 0; i < n; i++) {
if (!visc[i] && !visl[cur + i] && !visr[n + cur - i]) {
visc[i] = visl[cur + i] = visr[n + cur - i] = true;
search(cur + 1);
visc[i] = visl[cur + i] = visr[n + cur - i] = false;
}
}
}
int main() {
time_t tm;
cnt = 0;
scanf("%d", &n);
tm = clock();
search(0);
printf("cnt = %d\n", cnt);
printf("time is : %lf\n", (double)(clock() - tm) / CLOCKS_PER_SEC);
return 0;
}
#include <cstdio>
#include <ctime>
int cnt;
int n, uplimit;
void search(int r, int ld, int rd) {
if (r == uplimit) {
cnt++;
return ;
}
int cur = uplimit & ~(r | ld | rd);
while (cur) {
int p = cur & -cur;
cur ^= p;
search(r | p, (ld | p) << 1, (rd | p) >> 1);
}
}
int main() {
time_t tm;
scanf("%d", &n);
cnt = 0;
uplimit = (1 << n) - 1;
tm = clock();
search(0, 0, 0);
printf("cnt = %d\n", cnt);
printf("time is : %lf\n", (double)(clock() - tm) / CLOCKS_PER_SEC);
return 0;
}