Cod sursa(job #831729)

Utilizator sebii_cSebastian Claici sebii_c Data 9 decembrie 2012 01:16:32
Problema Dezastru Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.74 kb
#include <cstdio>

int n, k;
double res = 0.0;
double sol[25];
double v[25];
bool viz[25];

void generate(int len, int last)
{
    if (len == k) {
        double perm = 1.0;
        for (int i = 0; i < k; ++i)
            perm *= sol[i];
        res += perm;
    } else {
        for (int i = last; i < n; ++i) {
            if (viz[i])
                continue;
            viz[i] = true;
            sol[len] = v[i];
            generate(len + 1, i);
            viz[i] = false;
        }
    }
}

int main()
{
    freopen("dezastru.in", "r", stdin);
    freopen("dezastru.out", "w", stdout);

    scanf("%d %d", &n, &k);
    for (int i = 0; i < n; ++i)
        scanf("%lf", &v[i]);
    generate(0, 0);
    printf("%lf\n", res / n);
    
    return 0;
}