Pagini recente » Cod sursa (job #3211693) | Cod sursa (job #2489574) | Cod sursa (job #1042032) | Cod sursa (job #1648383) | Cod sursa (job #1474797)
#include <stdio.h>
int n, remaining, sol;
int c[13], maind[26], secd[26], pos[14];
inline int is_free(int x, int y) {
if (c[y]) return 0;
if (maind[n-1-(x-y)]) return 0;
if (secd[x+y]) return 0;
return 1;
}
void qbkt (int l) {
if (l == n) {
++sol;
if (sol == 1) {
for (int i = 0; i < n; ++i) {
printf("%d ", pos[i]+1);
}
printf("\n");
}
return;
}
for (int j = 0; j < n; ++j) {
if (is_free(l, j)) {
c[j] = maind[n-1-(l-j)] = secd[l+j] = 1;
pos[l] = j;
qbkt(l+1);
c[j] = maind[n-1-(l-j)] = secd[l+j] = 0;
}
}
}
int main (void) {
freopen("damesah.in", "r", stdin);
freopen("damesah.out", "w", stdout);
scanf("%d", &n);
qbkt(0);
printf("%d", sol);
return 0;
}