Cod sursa(job #2532001)

Utilizator memecoinMeme Coin memecoin Data 27 ianuarie 2020 05:14:07
Problema Dezastru Scor 70
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.05 kb
#include <fstream>
#include <string>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#include <map>
#include <string.h>
#include <queue>
#include <stack>

#define INF 0x3f3f3f3f

using namespace std;

#ifdef DEBUG
string name = "data";
#else
string name = "dezastru";
#endif

ifstream fin(name + ".in");
ofstream fout(name + ".out");

int n,k;

double p[50];

bool used[50];

double best = 0;
int cnt = 0;

void back(int i, int s) {
    if (s == k) {
        double pp = 1;
        for (int i = 0; i < n; ++i) {
            if (used[i]) {
                pp *= p[i];
            }
        }
        
        best += pp;
        cnt++;
        
        return;
    }
    
    if ((n - i) + s < k ) {
        return;
    }
    
    if (i >= n) {
        return;
    }
    
    used[i] = true;
    back(i + 1, s + 1);
    used[i] = false;
    back(i + 1, s);
}

int main() {
    
    fin >> n >> k;
    
    for (int i = 0; i < n; ++i) {
        fin >> p[i];
    }
    
    back(0, 0);
    
    fout << best / cnt;
    
    return 0;
}