Cod sursa(job #202470)

Utilizator alex_mircescuAlex Mircescu alex_mircescu Data 8 august 2008 20:56:30
Problema Dezastru Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.57 kb
#include <stdio.h>
#include <math.h>
  
long n, k, nfact, i;
double pg, p[64];

void back(int i, double pc, long ant){
	long j, lim = n - k + i + 1;
	double pl;
	for (j = ant + 1; j < lim; ++j) {
		pl = pc * p[j];
		if (i == k) {  
			pg += pl;
			++nfact;
		} else {
			back(i + 1, pl, j);
		}
	}
}

int main() {
	freopen("dezastru.in", "r", stdin);
    freopen("dezastru.out", "w", stdout);
    scanf("%ld %ld", &n, &k);
    for (i = 1;i <= n; ++i) {
		scanf("%lf", &p[i]);
    }
    back(1, 1.0, 0);
    printf("%lf\n", pg / nfact);
	return 0;
}