Cod sursa(job #1778600)

Utilizator andreinmAndrei andreinm Data 13 octombrie 2016 22:09:56
Problema Dezastru Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.89 kb
#include <bits/stdc++.h>
using namespace std;

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

short int N, K, i;
short int ans[25];
int cnt;
float plm;
float p[25];
float prob = 1, m;
//vector <float> v;

void backtr(int x) {
    if (x == K + 1) {
        for (int it = 1; it <= K; ++it)
            prob *= p[ans[it]];

  //      v.push_back(prob), v.push_back(prob);
        plm += prob;
        cnt++;
        prob = 1;
    } else {
        for (int i = ans[x-1] + 1; i <= N; ++i) {
            ans[x] = i;
            backtr(x + 1);
        }
    }
}

int main()
{
    in >> N >> K;
    for (i = 1; i <= N; ++i)
        in >> p[i];

    backtr(1);

 //   for (vector<float>::iterator it = v.begin(); it != v.end(); ++it)
 //       m += *it;

    out << setprecision(6) << fixed << plm / cnt;

    in.close();
    out.close();

    return 0;
}