Cod sursa(job #1770442)

Utilizator razvan242Zoltan Razvan-Daniel razvan242 Data 4 octombrie 2016 13:46:27
Problema Dezastru Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.66 kb
#include <bits/stdc++.h>

using namespace std;

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

const int NMAX = 26;

int n, K, nrsol;
bool used[NMAX];
double a[NMAX];
double p;

void back(int k, double x) {
    if (k == K + 1) {
        p += x;
        ++nrsol;
        return;
    }
    for (int i = 1; i <= n; ++i) {
        if (!used[i]) {
            used[i] = 1;
            back(k + 1, x * a[i]);
            used[i] = 0;
        }
    }
}

int main()
{
    fin >> n >> K;
    for (int i = 1; i <= n; ++i)
        fin >> a[i];
    back(1, 1.0);
    fout << fixed << setprecision(6) << p / (1.0 * nrsol);
    return 0;
}