Pagini recente » Cod sursa (job #767476) | Cod sursa (job #2193386) | Cod sursa (job #2871719) | Cod sursa (job #437158) | Cod sursa (job #2639701)
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("damesah.in");
ofstream out("damesah.out");
int n, c[14], nr = 0;
bool f = false;
void afisare() {
for (int i = 1; i <= n; i++)out << c[i] << ' ';
out << '\n';
}
void plasare(int a) {
if (a == n + 1) {
nr++;
if(f == false) afisare(), f = true;
}
else {
for (int i = 1; i <= n; i++) {
bool ok = true;
for (int j = 1; j < a && ok == true; j++) if (c[j] == i || abs(c[j] - i) == (a - j)) ok = false;
if (ok) {
c[a] = i;
plasare(a + 1);
}
}
}
}
int main() {
ios::sync_with_stdio(false);
in.tie(NULL), out.tie(NULL);
in >> n;
plasare(1);
out << nr;
return 0;
}