Cod sursa(job #265171)

Utilizator zlatebogdanZlate Bogdan zlatebogdan Data 23 februarie 2009 15:13:18
Problema Dezastru Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.53 kb
#include<cstdio>
int n,k,prod=1;
double a[30],sum=0;
void fact()
{
	int x=0,i;
	for(i=k+1;i<=n;++i)
	{
		x++;
		prod*=i;
		if (x<=n-k)
			if(prod%x==0)
				prod=prod/x;
	}
}
void back(int x,double q,int d)
{
	int i;
	if (x==k+1)
	{
		sum+=q;	
		prod++;
		return;
	}
	for(i=d+1;i<=n+x-k;++i)
		back(x+1,q*a[i],i);
}
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",&a[i]);
	//fact();
	back(1,1,0);
	printf("%lf",sum/prod);
	return 0;
}