Cod sursa(job #2214017)

Utilizator pacheprotopopescuPake Protopopescu pacheprotopopescu Data 18 iunie 2018 11:47:03
Problema Problema Damelor Scor 90
Compilator cpp Status done
Runda Arhiva educationala Marime 0.72 kb
#include <bits/stdc++.h>
using namespace std;
ifstream f("damesah.in");
ofstream g("damesah.out");
int n,st[100],a=0;
int cond(int k)
{
    for(int i=1;i<=k-1;i++)
        if(st[i]==st[k])return 0;
    for(int i=1;i<=k-1;i++)
        if(abs(k-i)==abs(st[k]-st[i]))return 0;
    return 1;
}
void afisare(int k)
{
    for(int i=1;i<=k;i++)
        g<<st[i]<<" ";
    g<<"\n";
}
void bt()
{
   int k=1;st[k]=0;
   while(k>0)
   {
       st[k]++;
       if(st[k]<=n)
       {
           if(cond(k))if(k==n){if(a==0)afisare(k);
                               a++;
                              }
            else {k++;st[k]=0;}
       }
       else k--;
   }
}
int main()
{
    f>>n;
    bt();
    g<<a;
}