Cod sursa(job #1927872)
| Utilizator | Data | 15 martie 2017 17:23:53 | |
|---|---|---|---|
| Problema | Problema Damelor | Scor | 90 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.86 kb |
#include <iostream>
#include <cmath>
#include <fstream>
using namespace std;
ifstream f("damesah.in");
ofstream g("damesah.out");
int n, x[100], c=0;
void afisare(int k)
{
if(c==0)
for(int i=1; i<=k; i++)
g<<x[i]<<" ";
}
int corect(int k)
{
for(int i=1; i<k; i++)
{
if(x[i]==x[k])
return 0;
if(k-i==abs(x[k]-x[i]))
return 0;
}
return 1;
}
void bk(int k)
{
for(int i=1; i<=n; i++)
{
x[k]=i;
if(corect(k))
if(k==n)
{
afisare(k);
c++;
}
else bk(k+1);
}
}
int main()
{
f>>n;
bk(1);
g<<endl;
g<<c;
}
