Cod sursa(job #276798)

Utilizator ooctavTuchila Octavian ooctav Data 11 martie 2009 12:40:31
Problema Dezastru Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.59 kb
// dezstru.cpp : Defines the entry point for the console application.
//

#include <stdio.h>
long n,k,val[30],cont=0;
float l,e[30],t=0;
void afisare()
{
	float d=1;
	for(int i=1;i<=k;i++)
		d=d*e[val[i]];
	cont ++;
	t=t+d;
}
void back( int a )
{
	if(a==k+1)
	{
		afisare();
		return ;
	}
	for(int i=val[a-1]+1;i<=n;i++)
	{
		val[a]=i;
		back(a+1);
	}
}
	
int main()
{
	int i;
	freopen("dezastru.in","r",stdin);
	freopen("dezastru.out","w",stdout);
	scanf("%ld %ld",&n,&k);
	for(i=1;i<=n;i++)
		scanf("%f ",&e[i]);
	back(1);
	l=t/cont;
	printf("%f",l);
	return 0;
}