Cod sursa(job #1292874)

Utilizator Al3ks1002Alex Cociorva Al3ks1002 Data 14 decembrie 2014 21:47:56
Problema Problema Damelor Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.14 kb
#include<cstdio>
#include<fstream>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<bitset>
#include<deque>
#include<queue>
#include<set>
#include<map>
#include<cmath>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<unordered_map>

#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

const int nmax = 55;

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;
}