Cod sursa(job #1728752)

Utilizator GoogalAbabei Daniel Googal Data 13 iulie 2016 16:38:36
Problema Dezastru Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.68 kb
#include <fstream>
#include <iomanip>

using namespace std;

double sum = 0;
int num = 0;
int n, k;
double x;
double v[26];


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

inline void back(int count, int i, double product)
{
    if (count == k)
    {
        sum += product;
        num++;
    }
    else
    {
        for (int j = i; j < n - k + count + 1; j++)
        {
            back(count + 1, j + 1, product * v[j]);
        }
    }
}

int main()
{

    fin >> n >> k;
    for (int i = 0; i < n; i++)
    {
        fin >> v[i];
    }

    back(0, 0, 1.0);


    fout << setprecision(7) << sum / num;

    return 0;
}