Cod sursa(job #3244562)

Utilizator FlaviuuuFlaviu Flaviuuu Data 25 septembrie 2024 15:27:49
Problema Problema Damelor Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.12 kb
#include <fstream>
#include <vector>
#include <map>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <set>
using namespace std;
ifstream cin("damesah.in");
ofstream cout("damesah.out");
#define ll long long
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
ll n;
vector<ll> a;
bool fr[15];
ll ans = 0;
bool ok = 0;
bool d1[50], d2[101];
void afisare()
{
    for(int i = 0; i < a.size(); i++)
        cout<<a[i]<<" ";
    cout<<'\n';
}
void bkt(int pas)
{
    if(pas == n)
        {if(ok == 0) afisare(), ok = 1; ans++; return;}
    for(int i = 1; i <= n; i++)
    {
        if(fr[i] == 0 && d1[i + pas + 1] == 0 && d2[pas + 1 - i + n] == 0)
        {
            fr[i] = 1;
            d1[i + pas + 1] = 1;
            d2[pas + 1 - i + n] = 1;
            a.push_back(i);
            bkt(pas + 1);
            d1[i + pas + 1] = 0;
            d2[pas + 1 - i + n] = 0;
            fr[i] = 0;
            a.pop_back();
        }
    }
}
int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>n;
    bkt(0);
    cout<<ans;
    return 0;
}