Cod sursa(job #354562)

Utilizator Alexa_ioana_14Antoche Ioana Alexandra Alexa_ioana_14 Data 8 octombrie 2009 19:21:14
Problema Dezastru Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.73 kb
#include<cstdio>
#define N 26
short int n,k,sol[N],inceput,t,b[30],num;
double v[N],g=1;
int lims,limi;
bool viz[N];
void citire()
{
	freopen("dezastru.in","r",stdin);
	freopen("dezastru.out","w",stdout);
	scanf("%hd%hd",&n,&k);
	for (short int i=1; i<=n; ++i)
		scanf("%lf",&v[i]);
	for (int i=1; i<=k; ++i)
	{
		lims+=1<<(n-i);
		limi+=1<<(i-1);
	}
}
void desc(int x)
{
	b[0]=0;
	num=0;
	while (x)
	{
		b[++b[0]]=x&1;
		if (b[b[0]])
			++num;
		if (num>k)
			return;
		x>>=1;
	}
	if (num!=k)
		return;
	g=1;
	++t;
	for (int i=1; i<=b[0]; ++i)
		if (b[i])
			g*=v[i];
	v[0]+=g;
}
int main()
{
	citire();
	for (int i=limi; i<=lims; ++i)
		desc(i);
	v[0]/=t;
	printf("%.6lf",v[0]);
	return 0;
}