Pagini recente » Cod sursa (job #1759439) | Cod sursa (job #2657694) | Cod sursa (job #2342856) | Cod sursa (job #2366371) | Cod sursa (job #3319321)
#include <iostream>
#include <fstream>
using namespace std;
int n, v[15];
bool col[15], d1[30], d2[30];
long long sol;
bool gasit = false;
ofstream fout("damesah.out");
void scrie() {
for(int i = 1; i <= n; i++)
fout << v[i] << (i == n ? '\n' : ' ');
}
void BT(int i) {
if(i > n) {
sol++;
if(!gasit) {
scrie();
gasit = true;
}
return;
}
for(int j = 1; j <= n; j++) {
if(!col[j] && !d1[i - j + n] && !d2[i + j]) {
v[i] = j;
col[j] = d1[i - j + n] = d2[i + j] = true;
BT(i + 1);
col[j] = d1[i - j + n] = d2[i + j] = false;
}
}
}
int main() {
ifstream fin("damesah.in");
fin >> n;
BT(1);
fout << sol << endl;
return 0;
}