Cod sursa(job #2548066)

Utilizator Bogdan.1108Mandresi Bogdan Bogdan.1108 Data 16 februarie 2020 10:34:22
Problema Dezastru Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.64 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 = (double)prb*prob[v[p]];
        if(p == k) {
            nr++;
            res = (double)res+newp;
        } else
            backtracking(p+1, newp);
    }
}

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