Cod sursa(job #150073)

Utilizator slayer4uVictor Popescu slayer4u Data 6 martie 2008 15:51:44
Problema Dezastru Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <stdio.h>

long i, j, k, l, a, n;
double s, x[32][32], c[32][32], p[32];

int main()
{
	freopen("dezastru.in", "rt", stdin);
	freopen("dezastru.out", "wt", stdout);

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

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

	x[1][1] = p[1];
	c[1][1] = c[1][0]= x[1][0] = 1;

	for (i = 2; i <= n; i ++)
	{
		x[i][0] = c[i][0] = 1;
		for (j = 1; j <= k && j <= i; j ++)
		{
			x[i][j] = x[i - 1][j] + x[i - 1][j - 1] * p[i];
			c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
		}
	}

	printf("%.6lf\n", x[n][k] / c[n][k]);

    return 0;
}