Cod sursa(job #68589)

Utilizator c_sebiSebastian Crisan c_sebi Data 28 iunie 2007 16:11:42
Problema Dezastru Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.57 kb
#include <stdio.h>

int n, k, nr, c[26];
double p[26], P=0, aux=1;

void comb (int i){
	int j;
	if (i==k+1) {
		//double aux=1;
		nr++; //for (j=1; j<=k; ++j) aux*=p[c[j]];
		P+=2*aux;}
	else for (j=c[i-1]+1; j<=n-k+i; ++j){
				c[i]=j; aux*=p[j];
				comb (i+1); aux/=p[j];
			}
}

int main() {
	int i;
	FILE *f=fopen ("dezastru.in", "r");
	FILE *g=fopen ("dezastru.out", "w");
	fscanf (f, "%d %d\n", &n, &k);
	for (i=1; i<=n; ++i) fscanf (f, "%lf ", &p[i]);
	c[0]=0;
	comb(1);
	P/=(2*nr);
	fprintf (g, "%lf\n", P);
	fclose(f);
	fclose(g);
	return 0;
}