Cod sursa(job #1040520)

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

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


void comb (int l) {
	int i=0;
	double prob=1;
	if (l==k) {
		for (i=1; i<=k; i++) {
			prob*=p[s[i]];
		}
		sum=sum+f[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=1; j<=n; j++) {
		scanf ("%lf ", &x);
		p[j]=x;
	}
	f[0]=f[1]=1;
	for (j=2; j<=n; j++) {
		f[j]=f[j-1]*j;
	}
	comb(0);
	
	printf ("%.*lf",6, sum/f[n]);
	
	
	
	return 0;
}