Pagini recente » Cod sursa (job #727377) | Cod sursa (job #705198) | Cod sursa (job #1453103) | Cod sursa (job #255409) | Cod sursa (job #2266426)
#include <fstream>
using namespace std;
ifstream fin("damesah.in");
ofstream fout("damesah.out");
int n;
int nrsol;
bool uc[14],udp[100],uds[100];
int sol[14];
bool esol;
void back(int lin) {
if(lin == n + 1){
nrsol++;
if(!esol) {
for(int i = 1; i <= n; i++) {
fout << sol[i] << " ";
}
fout << '\n';
esol = true;
}
return;
} else {
for(int col = 1; col <= n; col++) {
if(!uc[col] && !udp[col - lin + n - 1] && !uds[lin + col]) {
sol[lin] = col;
uc[col] = udp[col - lin + n - 1] = uds[lin + col] = true;
back(lin + 1);
uc[col] = udp[col - lin + n - 1] = uds[lin + col] = false;
}
}
}
}
int main(){
fin >> n;
back(1);
fout << nrsol;
}