Cod sursa(job #2386657)

Utilizator GabyD002Dobrita Gabriel GabyD002 Data 23 martie 2019 12:44:57
Problema Combinari Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.7 kb
#include <bits/stdc++.h>
#define NM 20
using namespace std;
ifstream f("a.in");
ofstream g("a.out");
int k,n,top,st[NM];
void Write()
{   for(int i=1; i<=n; i++) g<<st[i]<<' ';
    g<<'\n';
}
bool Valid()
{   for(int i=1; i<top; i++)
        if(st[i]==st[top]) return 0;
    return 1;
}
void BKT()
{   st[++top]=0;
    while(top && k)
    {   bool ok=0;
        while(!ok && st[top]<n)
        {   st[top]++;
            ok=Valid();
        }
        if(!ok) top--;
            else
                if(top==n)
                {   Write();
                    k--;
                }
                else st[++top]=0;
    }
}
int main()
{   f>>k>>n;
    BKT();
    return 0;
}