Cod sursa(job #2514622)

Utilizator vlad082002Ciocoiu Vlad vlad082002 Data 26 decembrie 2019 15:37:25
Problema Dezastru Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.61 kb
#include <fstream>
using namespace std;

ifstream fin("dezastru.in");
ofstream fout("dezastru.out");

int n, k, v[32], nr;
double prob[32], res;

void citire() {
    fin >> n >> k;
    for(int i = 1; i <= n; i++)
        fin >> prob[i];
}

void backtracking(int p, double prb) {
    for(int i = v[p-1]+1; i <= n; i++) {
        v[p]= i;
        double newp = prb*prob[v[p]];
        if(p == k) {
            nr++;
            res += newp;
        } else
            backtracking(p+1, newp);
    }
}

int main() {
    citire();
    backtracking(1, 1.0);
    res /= nr;
    fout << res;
}