Cod sursa(job #2602911)

Utilizator avtobusAvtobus avtobus Data 18 aprilie 2020 08:15:50
Problema Combinari Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.82 kb
#include <stdio.h>
#include <bits/stdc++.h>

#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int INF = 0x3f3f3f3f;

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

int N, k, d[20];

void write() {
  rep(i,k) { fout << d[i] << ' '; } fout << '\n';
}

void combinari(int pos, int lvl) {
  if (lvl == k) {
    write();
    return;
  }
  if (k - lvl == N - pos) {
    for(int j = lvl, i = pos; j < k; j++, i++) {
      d[j] = i+1;
    }
    write();
    return;
  }
  for(int i = pos; i < N; i++) {
    d[lvl] = i+1;
    combinari(i+1, lvl+1);
  }
}

int main(void) {
  // freopen("combinari.in", "r", stdin);
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(NULL);
  fin >> N >> k;
  combinari(0, 0);

  return 0;
}