Cod sursa(job #1455677)

Utilizator Player1Player 1 Player1 Data 28 iunie 2015 20:20:51
Problema Submultimi Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.85 kb
#include <stdio.h>

bool as,ev; 
int n,k,p;

void valid(int p, int v[]){
	int i;
	ev = true;
	if( p>0 && v[p]<=v[p-1])
		ev = false;
}

void suc(int p, int v[], bool &as){
	if( v[p]< n-k+p+1){
		v[p]++;
		as = true;
	} else
		as = false;
}

void tipar(int p, int v[]){
	int i;
	for(i = 0 ; i < k; i ++)
		printf("%d ", v[i]);
	printf("\n");
}

bool solutie(int p)
{
	if(p == k-1)
		return true;
	return false;
}

int main(){
	int v[17], j;

	freopen("submultimi.in","r",stdin);
	freopen("submultimi.out","w",stdout);

	scanf("%d ", &n);
	
	for(k=1;k<=n;k++){
		for(j=0;j<=n;j++)
			v[j] = 0;	
		p = 0;
		v[p] = 0;
		while( p>-1 ){ 
        		do{
				suc(p,v,as);
				if(as)
					valid(p,v);
			}while( as  && !(as && ev));
			if (as) {
				if (solutie(p))
					tipar(p,v);
				else {
					p++;
					v[p] = 0;
				}
			} else 
	            		p--;
		}
	}
	
	return 0;
}