Cod sursa(job #402795)

Utilizator lalasCont de teste lalas Data 24 februarie 2010 10:12:46
Problema Dezastru Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.68 kb
#include<cstdio>

const int maxn = 30;

int i , j , k , n;
double prob[maxn] , total , part ,act;
int s[maxn];

void calc () {
	int i;
	double rez = 1;
	
	for ( i = 1 ; i <= k ; ++i ) 
		rez *= prob[s[i]];
	
	total += rez;
}

void back (int p) {
	
	int i;
	
	if ( p == k + 1) calc();
	
	else { 
			for ( i = s[p - 1] + 1; i <= n ; ++i ) {
				s[p] = i;
				back (p + 1);
			}
	}
}
	

int main()
{
	freopen("dezastru.in","r",stdin);
	freopen("dezastru.out","w",stdout);
	
	scanf("%d %d",&n,&k);
	
	for( i = 1 ; i <= n ;++i ) 
		scanf("%lf",&prob[i]);
	
	back(1);
	
	for (i =  k + 1; i <= n ; ++i )
		total /= i;
	
printf("%lf\n",total);

return 0;
}