Cod sursa(job #1040515)

Utilizator andy1496Casu-Pop Andrei andy1496 Data 24 noiembrie 2013 16:38:19
Problema Dezastru Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.64 kb
#include <cstdio>
using namespace std;

	int n,k,s[26],j;
	double p[26],sum=0,x;

int fact (int x) {
	if (x==1) return 1;
	return x*fact(x-1);
}

void comb (int l) {
	int i=0;
	double prob=1;
	if (l==k) {
		for (i=1; i<=k; i++) {
			prob*=p[s[i]-1];
		}
		sum=sum+fact(k)*prob;
	}
	else {
		for (i=s[l]+1; i<=n; i++) {
			s[l+1]=i;
			comb(l+1);
		}
	}
}

int main ( ) {
	
	freopen ("dezastru.in", "r", stdin);
	freopen ("dezastru.out", "w", stdout);
	
	scanf ("%d %d\n", &n, &k);
	for (j=0; j<=n-1; j++) {
		scanf ("%lf ", &x);
		p[j]=x;
	}

	comb(0);
	
	printf ("%.*lf",6, sum/fact(n));
	
	
	
	return 0;
}