Cod sursa(job #1092039)
Utilizator | Alex Cociorva Al3ks1002 | Data | 26 ianuarie 2014 14:56:02 |
---|---|---|---|
Problema | Problema Damelor | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.65 kb |
#include<cstdio>
#include<bitset>
using namespace std;
const int NMAX = 15;
int N,St[NMAX],Sol;
bitset<NMAX> C,DP,DS;
void Back(int l)
{
if(l==N+1)
{
if(!Sol++)
{
for(int c=1;c<=N;c++) printf("%d ",St[c]);
printf("\n");
}
}
for(int c=1;c<=N;c++)
if(!C[c] && !DP[l-c+N] && !DS[l+c])
{
St[l]=c;
C[c]=DP[l-c+N]=DS[l+c]=1;
Back(l+1);
C[c]=DP[l-c+N]=DS[l+c]=0;
}
}
int main()
{
freopen("damesah.in","r",stdin);
freopen("damesah.out","w",stdout);
scanf("%d",&N); Back(1); printf("%d\n",Sol);
return 0;
}