Cod sursa(job #2170528)

Utilizator 24601Dan Ban 24601 Data 15 martie 2018 06:10:14
Problema Dezastru Scor 50
Compilator c Status done
Runda Arhiva de probleme Marime 0.78 kb
#include <stdio.h>

#define SIZE 25

static int n, k, c[SIZE], used[SIZE], ng;
static double p[SIZE], sum;

static void comb(int l)
{
    int i;
    double prod;

    if (l == k) {
        prod = 1.0;
        for (i = 0; i < l; i++) {
            prod *= p[c[i] - 1];
        }

        sum += prod;
        ng++;
    } else {
        for (i = 1; i <= n; i++) {
            if (!used[i]) {
                used[i] = 1;
                c[l] = i;
                comb(l + 1);
                used[i] = 0;
            }
        }
    }
}

int main(void)
{
    int i;

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

    scanf("%d %d", &n, &k);

    for (i = 0; i < n; i++) {
        scanf("%lf", &p[i]);
    }

    comb(0);

    printf("%lf", sum / ng);

    return 0;
}