Pagini recente » Statistici Onescu Iancu (onescu.iancu) | Cod sursa (job #2247333) | Cod sursa (job #941356) | Cod sursa (job #163391) | Cod sursa (job #2531370)
using namespace std;
#include<bits/stdc++.h>
ifstream fin("damesah.in");
ofstream fout("damesah.out");
int n, x[14], nrsol;
void tipar() {
for (int i = 1; i<=n; i++) {
fout << x[i] << " ";
}
fout << endl;
}
bool cont(int x[], int k) {
for (int i = 1; i<k; i++) {
if (x[i] == x[k] || (abs(x[k]-x[i]) == abs(k-i))) {
return 0;
}
}
return 1;
}
void bkt(int pos) {
if (pos > n) {
nrsol++;
if (nrsol == 1) {
tipar();
}
} else {
for (int i = 1; i<=n; i++) {
x[pos] = i;
if (cont(x,pos)) {
bkt(pos+1);
}
}
}
}
int main() {
fin >> n;
bkt(1);
fout << nrsol;
fin.close();
fout.close();
return 0;
}