Cod sursa(job #2173668)

Utilizator 24601Dan Ban 24601 Data 15 martie 2018 23:27:27
Problema Dezastru Scor 80
Compilator c Status done
Runda Arhiva de probleme Marime 0.69 kb
#include <stdio.h>

#define SIZE 25

static int n, k, c[SIZE+1], np;
static double p[SIZE], sum, prod = 1.0;

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

    if (l == k) {
        sum += prod;
        np++;
    } else {
        for (i = c[l] + 1; i + (k - l - 1) <= n; i++) {
            pprev = prod;
            prod *= p[i - 1];
            c[l + 1] = i;
            comb(l + 1);
            prod = pprev;
        }
    }
}

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 / np);

    return 0;
}