Cod sursa(job #422994)

Utilizator bog29Antohi Bogdan bog29 Data 23 martie 2010 13:27:45
Problema Dezastru Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.74 kb
#include<fstream>
#define dmax 30
using namespace std;
ifstream in("dezastru.in");
ofstream out("dezastru.out");

int n,m,cmb[dmax][dmax];
long long nr;
double x[dmax],mat[dmax][dmax],sol;

long long comb(int n,int k)
{	int i,j;
	cmb[1][0]=cmb[1][1]=1;
	for(i=2;i<=n;i++)
		for(j=0;j<=i;j++)
		{	if(j==0 || j==i)cmb[i][j]=1;
			else cmb[i][j]=cmb[i-1][j-1]+cmb[i-1][j];
		}
	return cmb[n][k];
}	

int main()
{	int i,j;
	in>>n>>m;
	for(i=1;i<=n;i++)
		in>>x[i];
	in.close();
	for(i=1;i<=n;i++)
		mat[i][1]=mat[i-1][1]+x[i];
	for(i=2;i<=m;i++)
		mat[1][i]=0;
	for(i=2;i<=n;i++)
		for(j=2;j<=m;j++)
			mat[i][j]=mat[i-1][j]+mat[i-1][j-1]*x[i];
	sol=mat[n][m]/(double)(comb(n,m));	
	out<<sol;
	out.close();
	return 0;
}