Cod sursa(job #3139706)

Utilizator ItsComplicatedMihai Ian ItsComplicated Data 1 iulie 2023 00:05:02
Problema Combinari Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.59 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream fin("combinari.in");
ofstream fout("combinari.out");

int used[20];
int v[20];
int n, k;

void printv() {
  for(int i = 1; i <= k; i++) {
    fout << v[i] << " ";
  }
  fout << endl;
}

void comb(int step) {
  if (step == k + 1) {
    printv();
    return;
  }
  for(int nr = v[step-1] + 1; nr <= n; nr++) {
    if (used[nr] == 0) {
      used[nr] = 1;
      v[step] = nr;
      comb(step + 1);
      used[nr] = 0;
    }
  }
}

int main()
{
    fin >> n >> k;

    comb(1);

    return 0;
}