Cod sursa(job #648733)

Utilizator mihaibogdan10Mihai Bogdan mihaibogdan10 Data 14 decembrie 2011 03:26:35
Problema Submultimi Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.52 kb
#include<cstdio>
using namespace std;

int n, st[17];

void Back(int top, int &k){
	if (top == k){ 
		for (int i = 0; i < top; i++) printf("%d ", st[i]);
		printf("\n");
	}
	
	for (int i = 1; i <= n; i++)
		if (top == 0 || i > st[top - 1]){
			st[top] = i;
			Back(top + 1, k);
		}
}

int main(){
	freopen("submultimi.in", "r", stdin), freopen("submultimi.out", "w", stdout);
	scanf ("%d", &n);
	
	//generez toate combinarile de n luate cate i cu i = 1,n
	for (int i = 1; i <= n; i++) Back(0, i);
	return 0;
}