Cod sursa(job #2505039)

Utilizator MatteoalexandruMatteo Verzotti Matteoalexandru Data 6 decembrie 2019 06:16:14
Problema Combinari Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.52 kb
/*
                `-/oo+/-   ``
              .oyhhhhhhyo.`od
             +hhhhyyoooos. h/
            +hhyso++oosy- /s
           .yoooossyyo:``-y`
            ..----.` ``.-/+:.`
                   `````..-::/.
                  `..```.-::///`
                 `-.....--::::/:
                `.......--::////:
               `...`....---:::://:
             `......``..--:::::///:`
            `---.......--:::::////+/`
            ----------::::::/::///++:
            ----:---:::::///////////:`
            .----::::::////////////:-`
            `----::::::::::/::::::::-
             `.-----:::::::::::::::-
               ...----:::::::::/:-`
                 `.---::/+osss+:`
                   ``.:://///-.
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cmath>

using namespace std;

const int INF = 2e9;

int n, k;
int f[20];
int sol[20];

void bkt(int x){
    if(x == k){
        for(int i = 0; i < k; ++i) printf("%d ", sol[i]);
        printf("\n");
        return;
    }
    for(int i = sol[x - 1]; i <= n; ++i){
        if(f[i]){
            sol[x] = i;
            f[i]--;
            bkt(x + 1);
            f[i]++;
        }
    }
}

int main()
{
    freopen("combinari.in", "r", stdin);
    freopen("combinari.out", "w", stdout);
    scanf("%d%d", &n, &k);

    for(int i = 1; i <= n; ++i) f[i] = 1;
    bkt(0);
    return 0;
}