Cod sursa(job #743394)

Utilizator andreidanAndrei Dan andreidan Data 4 mai 2012 10:13:57
Problema Dezastru Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.55 kb
#include<cstdio>
#define N 50
int A[N];
double V[N];
int n, k;
double pr=1,su=0;
int cont=0;

void afiseaza_solutie() {
	pr=1;
	for(int i = 1; i <= k; i++)
		pr*=V[A[i]];
	su=su+pr;
	cont++;
}


void back(int i) {
	for(int j = A[i-1]+1; j <= n; j++) {
		A[i] = j;
			if(i == k)
				afiseaza_solutie();
		   else
			   back(i + 1);
	}
}
int main() {
	int i;
	freopen("dezastru.in","r",stdin);
	freopen("dezastru.out","w",stdout);
	
	scanf("%d %d",&n,&k);
	for(i=1;i<=n;++i)
		scanf("%lf", &V[i]);
	back(1);
	printf("%lf", su/cont);
}