Cod sursa(job #1369088)

Utilizator iordache.bogdanIordache Ioan-Bogdan iordache.bogdan Data 2 martie 2015 21:41:05
Problema Dezastru Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <fstream>
#include <algorithm>
#include <iomanip>

#define DIM 30
#define infile "dezastru.in"
#define outfile "dezastru.out"

using namespace std;

ifstream f(infile);
ofstream g(outfile);

double dp[DIM][DIM], comb[DIM][DIM], prob[DIM];

int main() {

	int n, k;

	f >> n >> k;

	for (int i = 1; i <= n; ++i)
		f >> prob[i];

	for (int i = 1; i <= n; ++i) {

		dp[i - 1][0] = 1;

		comb[i - 1][0] = 1;

		for (int j = 1; j <= k; ++j) {

			dp[i][j] = dp[i - 1][j - 1] * prob[i] + dp[i - 1][j];
			comb[i][j] = comb[i - 1][j] + comb[i - 1][j - 1];

		}

	}

	g << setprecision(6) << fixed;

	g << dp[n][k] / comb[n][k] << "\n";

	return 0;
}

//Trust me, I'm the Doctor!