Cod sursa(job #221247)

Utilizator adelinavVidovici Adelina adelinav Data 15 noiembrie 2008 12:28:54
Problema Dezastru Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.63 kb
#include<stdio.h>

int n,m,st[100];
long double p[100],sp;

void solutie(){
	long double pr=1;
	for(int i=1;i<=m;i++)
		pr=pr*p[st[i]];
	sp=sp+pr;
}

void bkt(int k,int x){
	if(k==m+1) solutie();
	else {
			st[k]=x;
			while(st[k]<n-m+k) {st[k]++;
								bkt(k+1,st[k]);
			}
	}
}

int comb(int x,int y){
if(y==0||x==y) return 1;
else return comb(x-1,y-1)+comb(x-1,y);
}


int main(){
int i,c;
long double s=0;
freopen("dezastru.in","r",stdin);
freopen("dezastru.out","w",stdout);
scanf("%d%d",&n,&m);
for(i=1;i<=n;i++)
	scanf("%Lf",&p[i]);
c=comb(n,m);
bkt(1,0);
s=sp/c;
printf("%Lf",s);
return 0;
}