Cod sursa(job #3348626)

Utilizator G_b_yZamfirache Gabriel G_b_y Data 23 martie 2026 10:20:12
Problema Dezastru Scor 50
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.85 kb
#include <bits/stdc++.h>

using namespace std;

double probs[30];
int N, K;
int indexes[30];
bool viz[30];

double total = 0;
int cnt = 0;

void bckt (int i = 0) {
    if (i == K) {
        double temp = 1;
        for (int j = 0; j < K; ++j) {
            temp *= probs[indexes[j]];
        }
        total += temp;
        cnt++;
        return;
    }
    for (int k = 0; k < N; ++k) {
        if (!viz[k]) {
            indexes[i] = k;
            viz[k] = true;
            bckt(i + 1);
            viz[k] = false;
        }
    }
}

int main() {
    freopen("dezastru.in", "r", stdin); freopen("dezastru.out", "w", stdout); cin.tie(NULL); cout.tie(NULL);

    cin >> N >> K;
    for (int i = 0; i < N; ++i) {
        cin >> probs[i];
    }

    bckt();
    cout << fixed << setprecision(6) << total / cnt;

    return 0;
}