Cod sursa(job #1006818)

Utilizator Darius15Darius Pop Darius15 Data 7 octombrie 2013 20:03:24
Problema Combinari Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.64 kb
#include <fstream>//var II
#include <cmath>

using namespace std;
ifstream f("combinari.in");
ofstream g("combinari.out");
int n, k, a[19];

void init (int l) {
  a[l] = l-1;
}

bool succesor (int l) {
  a[l]++;
  return a[l] < n-(k-l)+1;
}

bool valid (int l) {

    return a[l-1] < a[l];
}

bool sol (int l) {
  return l == k;
}

void tip () {
  int i;

  for (i = 1; i <= k; i++)
    g << a[i] << ' ';
  g << '\n';
}

void bt (int l) {
  init (l);
  while (succesor(l))
    if (valid(l))
      if (sol(l))
        tip();
      else
        bt(l+1);
}
int main()

{
    f>>n>>k;
    bt(1);
    return 0;
}