Cod sursa(job #2521019)

Utilizator mirceatlxhaha haha mirceatlx Data 10 ianuarie 2020 11:13:57
Problema Dezastru Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.65 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;
}