Cod sursa(job #1770446)

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

using namespace std;

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

const int NMAX = 26;

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

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

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