Cod sursa(job #1927884)

Utilizator GandalfTheWhiteGandalf the White GandalfTheWhite Data 15 martie 2017 17:34:33
Problema Combinari Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.53 kb
#include <cstdio>
#include <vector>
using namespace std;

int n,k,st[20];
void Read(){

    freopen("combinari.in","r",stdin);

    scanf("%d%d",&n,&k);
}

void Write(){

    int i;

    for (i=1;i<=k;++i)
        printf("%d ",st[i]);
    printf("\n");
}

void back(int top){

    for (int i=st[top-1]+1;i<=n-k+top;i++){
        st[top]=i;
        if (top==k) Write();
        else back(top+1);
        }
}
int main()
{
    freopen("combinari.out","w",stdout);
    Read();
    back(1);
    return 0;
}