Cod sursa(job #932632)

Utilizator h2g2Ford Prefect h2g2 Data 29 martie 2013 08:27:41
Problema Combinari Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.55 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#define nmax 20
using namespace std;

ifstream f("combinari.in");
ofstream g("combinari.out");
int st[nmax], n, k;

void tipar() { for(int i=1; i<=k; i++) g<<st[i]<<" "; g<<"\n"; }

bool valid(int h) {
	for(int i=0; i<h; i++) if(st[i]>=st[h]) return false;
	return true;
}

void back(int h) {
	for(int i=1; i<=n; i++) {	
		st[h] = i;
		if(valid(h)) {
			if(h==k) tipar();
			else back(h+1);
		}
	}
}

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

	back(1);

	return 0;
}