Cod sursa(job #461294)

Utilizator AndreiRSStatescu Andrei Rares AndreiRS Data 6 iunie 2010 11:29:50
Problema Dezastru Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.55 kb
#include <stdio.h>
#define DIMBACK 1<<5

int X[DIMBACK], viz[DIMBACK];
int N, K, NRCOMB; 
double A[DIMBACK], PROB;

void back (int k, double probs){
	int i;
	if (k - 1 == K)	PROB += probs, ++NRCOMB;
	
	for (i=X[k-1]+1; i<=N; i++){
		X[k] = i;
		
		back (k + 1, probs * A[i]);
	}
}

int main (){
	
	freopen ("dezastru.in", "r", stdin);
	freopen ("dezastru.out", "w", stdout);
	
	scanf ("%d %d\n", &N, &K);
	
	for (int i=1; i<=N; i++) scanf ("%lf", &A[i]);
	
	back (1, 1.0);
	
	printf ("%.6lf", PROB / (double)NRCOMB);

	return 0;
}