Cod sursa(job #2025606)

Utilizator shantih1Alex S Hill shantih1 Data 22 septembrie 2017 21:56:00
Problema Dezastru Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <iostream>
#include <fstream>

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

long long cst;
double dz, s, v[30], sum;
int tot, n, k, i, j, d[30];

long long factorial (int x)
{
    if (x == 1) return 1;
    else return x * factorial(x-1);
}

int calc () {
    
    double po = 1;
    for (int i = 1; i <= k; i++)
        po *= v[d[i]];

    tot++;  sum += po;
    return po;
}

void back (int p) {
    
    for (int i = d[p-1]+1; i <= n; i++)
    {
        d[p] = i;
        if (p == k)     calc();
        else back (p+1);
    }
}

int main () {
    
    fin >> n >> k;
    for (i = 1; i <= n; i++)
        fin >> v[i];
    back(1);
    fout << sum/tot << "\n";
    return 0;
}