Cod sursa(job #1172653)

Utilizator nimicLeoveanu Mihaita Alexandru nimic Data 17 aprilie 2014 20:50:50
Problema Dezastru Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.69 kb
#include<fstream>
#include<iomanip>
using namespace std;
ifstream in("dezastru.in");
ofstream out("dezastru.out");

const int nmax = 32;
long long comb[nmax][nmax];
double a[nmax][nmax], v[50], rasp;
int n, k;

int main()
{
    int player_unu=0;

    in>>n>>k;
    for (int i = 1; i<=n; i++)
		in>>v[i];

    for (int i = 0; i<=n; i++)
		a[i][0] = 1, comb[i][0] = 1;

    for (int i = 1; i<=n; i++)
	{
        for (int j = 1; j<=k; j++)
        {
            a[i][j] = (a[i-1][j] + a[i-1][j-1] * v[i]);
            comb[i][j] = comb[i-1][j] + comb[i-1][j-1];
        }
	}

    rasp = a[n][k]/(double)comb[n][k];
    out<<rasp<<setprecision(6)<<fixed;
    return player_unu;
}