Cod sursa(job #2047170)

Utilizator AndreiG23Ghiurcuta Andrei AndreiG23 Data 24 octombrie 2017 17:06:12
Problema Combinari Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.78 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("combinari.in");
ofstream fout("combinari.out");
int n,st[105],k,p;
void init()
{
    st[k]=0;
}
int succesor()
{
    if(st[k]<n){st[k]++;return 1;}
    else return 0;
}
int valid()
{
    for(int i=1;i<k;i++)
    if(st[k]==st[i])return 0;
        if(k>1&&(st[k]<st[k-1]))return 0;

    return 1;
}
int solutie()
{
    return(k==p);
}
void tipar()
{
    for(int i=1;i<=p;i++)
        fout<<st[i]<<' ';
    fout<<'\n';
}
void BK()
{
    int as;
    k=1;init();
    while(k>0)
    {
        do{}while((as=succesor())&&!valid());
            if(as)
            if(solutie())tipar();
        else{k++;init();}
        else k--;
    }
}
int main()
{
    fin>>n>>p;
    BK();
}