Mai intai trebuie sa te autentifici.
Cod sursa(job #2517922)
Utilizator | Data | 4 ianuarie 2020 15:13:49 | |
---|---|---|---|
Problema | Problema Damelor | Scor | 90 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.77 kb |
#include <iostream>
#include <fstream>
#include <stdlib.h>
using namespace std;
ifstream fin("damesah.in");
ofstream fout("damesah.out");
int n, sol[20], nr = 0;
void afisare()
{
for(int j = 1; j <= n; j++)
fout << sol[j] << " ";
fout << "\n";
}
int verifica(int k)
{
for(int j = 1; j < k; j++)
if(sol[k] == sol[j] || abs(j - k) == abs(sol[j] - sol[k]))
return 0;
return 1;
}
void solve(int poz)
{
if(poz == n + 1)
{
if(nr == 0)
afisare();
nr++;
}
else
for(int i = 1; i <= n; i++)
{
sol[poz] = i;
if(verifica(poz))
solve(poz + 1);
}
}
int main()
{
fin >> n;
solve(1);
fout << nr;
return 0;
}