Cod sursa(job #832501)

Utilizator mihai995mihai995 mihai995 Data 10 decembrie 2012 19:41:29
Problema Dezastru Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.57 kb
#include <fstream>
#include <cstdio>
using namespace std;

const int N = 1001;
double p[N], prob;
int n, k, nrP;

ifstream in("dezastru.in");

void bkt(int poz, double P, int L){
    if (poz == k + 1){
        prob += P;
        ++nrP;
        return;
    }

    for (int i = 1 + L ; i <= n - k + poz ; i++)
        bkt(poz + 1, P * p[i], i);
}

int main(){
    in >> n >> k;

    for (int i = 1 ; i <= n ; i++)
        in >> p[i];

    bkt(1, 1, 0);

    freopen("dezastru.out", "w", stdout);

    printf("%.6lf\n", prob / nrP);

    return 0;
}