Pagini recente » Cod sursa (job #3161271) | Cod sursa (job #3235024) | Cod sursa (job #2714043) | Cod sursa (job #578515) | Cod sursa (job #2853938)
#include <fstream>
#include <iostream>
using namespace std;
ifstream fin("damesah.in");
ofstream fout("damesah.out");
int k, n, cnt;
bool verif(int nivel, int sol[])
{
for(int j = 0; j < nivel; j++)
if(sol[nivel] == sol[j] || sol[nivel] + nivel == j + sol[j] || nivel - sol[nivel] == j - sol[j])
return false;
return true;
}
void afisare(int n, int sol[])
{
for(int i = 0; i < n; i++)
fout << sol[i] << ' ';
fout << '\n';
}
void it(int k, int & cnt) {
int sol[14] = {0};
int nivel = 0;
bool afisat = false;
cnt = 0;
while (nivel >= 0) {
if (nivel == k) {
cnt++;
if(!afisat){
afisare(k, sol);
afisat = true;
}
--nivel;
}
else{
++sol[nivel];
if (sol[nivel] <= k)
{
if(verif(nivel, sol))
++nivel;
}
else {
sol[nivel] = 0;
--nivel;
}
}
}
}
int main()
{
fin >> n;
it(n, cnt);
fout << cnt;
return 0;
}