Cod sursa(job #2886407)

Utilizator ElizaTElla Rose ElizaT Data 7 aprilie 2022 18:53:33
Problema Problema Damelor Scor 90
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.76 kb
#include <bits/stdc++.h>

using namespace std;

ofstream fout("damesah.out");

int n;
long long cnt = 0;
int c[20],l[20],d1[20],d2[20],q[20];

void bkt(int poz) {
    if (poz == n) {
        if (cnt == 0) {
            for (int i = 0;i < n;i++)
                fout << q[i] + 1 << " ";
            fout << '\n';
        }
        cnt++;
        return;
    }
    for (int i = 0;i < n;i++) {
        if (!c[i] && !d1[i - poz + n - 1] && !d2[i + poz]) {
            q[poz] = i;
            c[i] = d1[i - poz + n - 1] = d2[i + poz] = 1;
            bkt(poz + 1);
            c[i] = d1[i - poz + n - 1] = d2[i + poz] = 0;
        }
    }
}
int main()
{
    ifstream fin("damesah.in");
    fin >> n;
    bkt(0);
    fout << cnt;
    return 0;
}