Cod sursa(job #398467)

Utilizator robertzelXXX XXX robertzel Data 18 februarie 2010 19:37:23
Problema Combinari Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.61 kb
#include <iostream>
#include <stdio.h>

#define NMAX 19

using namespace std;

int n,k,nr[NMAX];

void back(int x) {

    if (x==k) {

        for (int i=1; i<=k; i++) {
            fprintf(stdout, "%d ", nr[i]);
        }

        fprintf(stdout, "\n");

    } else {

        for (int i=nr[x]+1; i<=n; i++) {
            nr[x+1] = i;
            back(x+1);
        }
    }
}

int main()
{
    freopen("combinari.in","r",stdin);
    freopen("combinari.out","w", stdout);

    fscanf(stdin, "%d %d", &n, &k);

    back(0);

    fclose(stdin);
    fclose(stdout);

    return 0;
}