Cod sursa(job #730972)

Utilizator lucian666Vasilut Lucian lucian666 Data 7 aprilie 2012 11:24:41
Problema Dezastru Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.61 kb


#include<fstream>
#include<cstdio>
using namespace std;
int n,k1,x[26];
double p[26],prob,probfinal;
long long nrc;

void back(int);
void solve();
void read();
void out();
int main()
{
	read();
	back(1);
	out();
	return 0;
}
void read()
{
	freopen("dezastru.in","r",stdin);
	scanf("%d%d",&n,&k1);
	for(int i=1;i<=n;i++)
		scanf("%lf",&p[i]);
}
void back(int k)
{
	for(int i=x[k-1]+1;i<=n;i++)
	{
		x[k]=i;
		if(k==k1)
			solve();
		else
			back(k+1);
	}
}
void solve()
{
	++nrc;
	prob=1;
	for(int i=1;i<=k1;i++)
	{	prob*=p[x[i]];}
	
	probfinal+=prob;
}
void out()
{
	ofstream out("dezastru.out");
	out<<probfinal/nrc;
}