Pagini recente » Cod sursa (job #3038760) | Cod sursa (job #2201159) | Cod sursa (job #3226225) | Cod sursa (job #2080967) | Cod sursa (job #2632632)
//#include <iostream>
#include <cmath>
#include <fstream>
using namespace std;
ifstream cin("damesah.in");
ofstream cout("damesah.out");
int sol[15];
int n, nr_solutii;
bool verif(int pas)
{
for (int i = 1; i < pas; i++)
if (sol[i] == sol[pas] || abs(i - pas) == abs(sol[i] - sol[pas]))
return false;
return true;
}
void bkt(int pas)
{
if (pas == n + 1)
{
if (!nr_solutii)
{
for (int i = 1; i <= n; i++)
cout << sol[i] << ' ';
cout << '\n';
}
nr_solutii++;
}
else
{
for (int k = 1; k <= n; k++)
{
sol[pas] = k;
if (verif(pas))
{
bkt(pas + 1);
}
}
}
}
int main()
{
cin >> n;
bkt(1);
cout << nr_solutii;
}