Cod sursa(job #2322848)
| Utilizator | Data | 18 ianuarie 2019 14:58:07 | |
|---|---|---|---|
| Problema | Problema Damelor | Scor | 90 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.63 kb |
#include <fstream>
#include <algorithm>
using namespace std;
ifstream f("damesah.in");
ofstream g("damesah.out");
int n,d,tot,stk[14];
bool ok;
bool verif(int i,int k)
{
for(d=1; d<k; ++d)
if(abs(i-stk[d])==k-d || i==stk[d])
return 0;
return 1;
}
void btk(int k)
{
if(k>n)
{
++tot;
if(!ok)
{
for(d=1; d<=n; ++d)
g<<stk[d]<<' ';
ok=1;
}
}
else
for(int i=1; i<=n; ++i)
if(verif(i,k))
stk[k]=i,btk(k+1);
}
int main()
{
f>>n;
btk(1);
g<<'\n'<<tot;
}
