Pagini recente » Cod sursa (job #520165) | Cod sursa (job #2045616) | Cod sursa (job #703240) | Cod sursa (job #2813182) | Cod sursa (job #2833163)
#include <fstream>
#include <iostream>
using namespace std;
ifstream fin("damesah.in");
ofstream fout("damesah.out");
int k, n, col[14];
bool verif(int i, int nivel, int col[])
{
for(int j = 0; j < nivel; j++)
if(i == col[j] || i + nivel == j + col[j] || nivel - i == j - col[j])
return false;
return true;
}
void afisare(int n, int col[])
{
for(int i = 0; i < n; i++)
fout << col[i] << ' ';
}
void f(int nivel, int n, int col[])
{
for (int i = 1; i <= n; i++)
if (verif(i, nivel, col))
{
col[nivel] = i;
if (nivel == n-1)
{
if(!k)
afisare(n, col);
k++;
}
else
f(nivel+1, n, col);
}
}
int main()
{
fin >> n;
f(0, n, col);
fout << '\n' << k;
return 0;
}