Cod sursa(job #735435)

Utilizator PatrunjeluMarginean Bogdan Alexandru Patrunjelu Data 16 aprilie 2012 14:36:43
Problema Combinari Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.65 kb
#include <stdio.h>
using namespace std;

short int n, k;
short int solutie[18];

void scriesolutie()
{
    for (short int i = 1; i <= k-1; ++i)
    {
        printf("%hd ", solutie[i]);
    }
    printf("%hd\n", solutie[k]);
}

void back(short int pas)
{
    if (pas == k)
    {
        scriesolutie();
    }
    else
    {
        for (short int i = solutie[pas] + 1; i <= n; ++i)
        {
            solutie[pas+1] = i;
            back(pas+1);
        }
    }
}

int main()
{
    freopen("combinari.in", "r", stdin);
    freopen("combinari.out", "w", stdout);
    scanf("%hd%hd", &n, &k);
    back(0);
    return 0;
}