Cod sursa(job #1926744)
| Utilizator | Data | 14 martie 2017 17:33:25 | |
|---|---|---|---|
| Problema | Problema Damelor | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.67 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream f("damesah.in");
ofstream g("damesah.out");
int sol,n,a[30],b[30],c[30],d[30];
void linia(int );
int main()
{
f>>n;
linia(1);
g<<sol;
return 0;
}
void linia(int L)
{
int C;
if(L==n+1)
{
sol++;
if(sol==1)
{
for(C=1;C<=n;C++)
g<<d[C]<<' ';
g<<'\n';
}
return ;
}
for(C=1;C<=n;C++)
{
if(a[C])continue;
if(b[n+C-L])continue;
if(c[C+L-1])continue;
a[C]=b[n+C-L]=c[C+L-1]=1;d[L]=C;
linia(L+1);
a[C]=b[n+C-L]=c[C+L-1]=0;
}
}
