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