Cod sursa(job #3361730)

Utilizator Alias47John Doe Alias47 Data 28 iulie 2026 09:11:00
Problema Problema Damelor Scor 90
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.89 kb
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ft(n) for(int i=1; i<=n; i++)
#define sp ' '
string file = "damesah";
ifstream f(file + ".in");
ofstream g(file + ".out");

int n, ct = 0;
vector<int> v(20);

void write()
{
    ct++;
    if (ct == 1) {
        for (int i = 1; i <= n; i++)
            g << v[i] << sp;
        g << "\n";
    }
}

void bkt(int i)
{
    for (int j = 1; j <= n; j++)
    {
        v[i] = j;
        //check
        bool chk = 1;
        int ci = i;
        for (int i = 1; i < ci; i++)
            if (v[ci] == v[i])
                chk = 0;
            else if (abs(v[ci] - v[i]) == abs(ci - i))
                chk = 0;
        if (chk)
            if (i == n)
                write();
            else
                bkt(i + 1);
    }
}

int main() {
    f >> n;
    bkt(1);
    g << ct;
    return 0;
}