Cod sursa(job #348762)

Utilizator bog29Antohi Bogdan bog29 Data 16 septembrie 2009 19:38:25
Problema Dezastru Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.54 kb
#include<fstream>
#define dmax 29
using namespace std;
ifstream in("dezastru.in");
ofstream out("dezastru.out");
int n,k,x[dmax];
float pr[dmax],a,b,prb;
bool t[dmax];
void cmb(int p)
{	int i;
	float z=1;
	if(p==k+1)
	{	for(i=1;i<=k;i++)
			z*=pr[x[i]];
		a+=z;
		b++;
	}
	else
	{	for(i=1;i<=n;i++)
		{	if(!t[i])
			{	t[i]=1;
				x[p]=i;
				cmb(p+1);
				t[i]=0;
			}
		}	
	}
}	
int main()
{	int i;
	in>>n>>k;
	for(i=1;i<=n;i++)
		in>>pr[i];
	in.close();
	cmb(1);
	prb=a/b;
	out<<prb;
	out.close();
	return 0;
}