Pagini recente » Cod sursa (job #2540141) | Cod sursa (job #2438526) | Cod sursa (job #1084648) | Cod sursa (job #2199249) | Cod sursa (job #2833154)
#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 f(int nivel, int n, int col[])
{
if (nivel == n)
{
if(!k)
for (int i = 0; i < n; i++)
fout << col[i] << ' ';
k++;
}
else
for (int i = 1; i <= n; i++)
{
bool ok = true;
for(int j = 0; j < nivel && ok; j++)
if(i == col[j] || i + nivel == j + col[j] || nivel - i == j - col[j])
ok = false;
if(ok)
{
col[nivel] = i;
f(nivel+1, n, col);
}
}
}
int main()
{
fin >> n;
f(0, n, col);
fout << '\n' << k;
return 0;
}