Cod sursa(job #2173640)

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

#define SIZE 25

static int n, k;
static double p[SIZE], sum, prod;

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

    if (l == k) {
        sum += prod;
        prod = 1.0;
    } else {
        for (i = pp; i + (k - l - 1) <= n; i++) {
            pprev = prod;
            prod *= p[i];
            comb(l + 1, i + 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]);
    }

    prod = 1.0;
    comb(0, 0);

    for (i = 2; i <= n - k; i++) {
        sum *= i;
    }

    for (i = k + 1; i <= n; i++) {
        sum /= i;
    }

    printf("%lf", sum);

    return 0;
}