Cod sursa(job #479467)

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

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

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

void bkt(int x,int nr,float p)
{
	if (!nr)
	{
		s+= 2*p;
		Nr+=2;
		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("%.6f\n",s);
	fclose(stdout);
}

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