Cod sursa(job #179675)

Utilizator Iceman_ftgBurghelea Alex Iceman_ftg Data 16 aprilie 2008 11:07:13
Problema Dezastru Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.52 kb
#include <fstream.h>
#include <iomanip.h>
ifstream fin("dezastru.in");
ofstream fout("dezastru.out");
int c[27][27],n,k;
double a[27][27],prob[27];
void citire()
{
fin>>n>>k;
int i;
for(i=1;i<=n;i++)
fin>>prob[i];
k++;}
void PD()
{
int i,j;
c[0][1]=1;
a[0][1]=1.0;
for(i=1;i<=n;i++)
	for(j=1;j<=k;j++)
		{
		c[i][j]=c[i-1][j-1]+c[i-1][j];
		a[i][j]=a[i-1][j-1]*prob[i]+a[i-1][j];
		}
}
void scriere()
{
fout<<setprecision(6)<<a[n][k]/c[n][k];
}
int main()
{
citire();
PD();
scriere();
return 0;
}