Cod sursa(job #2028062)

Utilizator OldpugAlex Ionescu Oldpug Data 27 septembrie 2017 08:53:11
Problema Combinari Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.55 kb
#include <fstream>
#define var auto

std::ofstream out("combinari.out");
int n, k, *comb;
bool *seen;

void BT(int pos)
{
  if (pos > k)
  {
    for (var i = 1; i <= k; ++i)
      out << comb[i] << ' ';
    out << '\n';
  }
  else
  {
    for (var i = 1; i <= n; ++i)
      if (!seen[i] && comb[pos - 1] < i)
      {
        comb[pos] = i;
        seen[pos] = true;

        BT(pos + 1);
        seen[pos] = false;
      }
  }
}

int main()
{
  std::ifstream in("combinari.in");

  in >> n >> k;
  comb = new int[k + 1];
  seen = new bool[n + 1];

  BT(1);
}