Cod sursa(job #479470)

Utilizator crushackPopescu Silviu crushack Data 24 august 2010 09:17:10
Problema Dezastru Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.63 kb
#include <stdio.h>
#define NMax 25

const char IN[]   ="dezastru.in";
const char OUT[]  ="dezastru.out";

int N,K,Nr;
float a[NMax];
double s;

void bkt(int x,int nr,float p)
{
	if (!nr)
	{
		s+= 2*p;
		Nr+=2;
		return;
	}
	
	if (nr>N-x) return;
	
	int i;
	for (i=x;i<N;i++)
		bkt(i+1,nr-1,p*a[i]);
	
}

void citire()
{
	int i;
	freopen(IN,"r",stdin);
	scanf("%d%d",&N,&K);
	for (i=0;i<N;i++)
		scanf("%f",&a[i]);
	fclose(stdin);
}

void scriere()
{
	freopen(OUT,"w",stdout);
	printf("%.6lf\n",s);
	fclose(stdout);
}

int main()
{
	citire();
	bkt(0,K,1);
	s/=Nr;
	scriere();
	return 0;
}