Cod sursa(job #2253512)

Utilizator ioncelciucCiuc Ionut-Tiberiu ioncelciuc Data 4 octombrie 2018 09:18:51
Problema Problema Damelor Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.67 kb
#include <bits/stdc++.h>

using namespace std;

int st[20],n,m;

void Afisare(int top)
{
    if(st[1]!=0)
    {
        for(int i=1;i<=top;i++)
            cout<<st[i];
        cout<<"\n";
    }
}

int Valid(int top,int x)
{
    if(top>1)
    {
        if(abs(st[top-1]-x)<2) return 0;
    }
    return 1;
}

void Back(int top)
{
    if(top==n+1)
        Afisare(n);
    else for(int i=0;i<m;i++)
    {
        if(Valid(top,i))
        {
            if(top==1 && i==0) ;
            else {
                st[top]=i;
                Back(top+1);
            }
        }
    }
}

int main()
{
    cin>>n>>m;
    Back(1);
    return 0;
}