Pagini recente » Cod sursa (job #1926768) | Cod sursa (job #873168) | Cod sursa (job #1991828) | Cod sursa (job #2731431) | Cod sursa (job #2632633)
//#include <iostream>
#include <cmath>
#include <fstream>
using namespace std;
ifstream cin("damesah.in");
ofstream cout("damesah.out");
int sol[15];
int n, nr_solutii;
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;
bool ok = true;
for (int i = 1; i < pas; i++)
if (sol[i] == sol[pas] || abs(i - pas) == abs(sol[i] - sol[pas]))
ok = false;
if (ok)
{
bkt(pas + 1);
}
}
}
}
int main()
{
cin >> n;
bkt(1);
cout << nr_solutii;
}