Cod sursa(job #1880080)

Utilizator wilson182Alexandrina Panfil wilson182 Data 15 februarie 2017 14:22:49
Problema Dezastru Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <bits/stdc++.h>
#define N 26
using namespace std;
double t[N], a[N][N];
int comb[N][N];
int main()
{
    freopen("dezastru.in", "r", stdin);
    freopen("dezastru.out", "w", stdout);
    int i, n, k, j;
    scanf("%d%d", &n, &k);
    for(i=1;i<=n;i++) {
    	scanf("%lf", &t[i]);
	}
    a[1][1]=t[1];
    a[1][0]=comb[1][0]=1;
    comb[1][1]=1;
	for(i=2;i<=n;i++){
		comb[i][0] = a[i][0]=1;
		for(j=1;j<=k;j++){
			a[i][j]=a[i-1][j]+t[i]*a[i-1][j-1];
			comb[i][j]=comb[i-1][j] + comb[i-1][j-1];
		}
	}
	printf("%lf ", a[n][k]/comb[n][k]);
	return 0;
}