Cod sursa(job #1692276)

Utilizator krityxAdrian Buzea krityx Data 20 aprilie 2016 16:38:39
Problema Dezastru Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <cstdio>

using namespace std;

double sum = 0, v[26];
int num = 0, n, k;

inline void back(int count, int i, double product)
{
	if (count == k)
	{
		sum += product;
		num++;
		return;
	}
	for (int j = i; j < n - k + count + 1; j++)
	{
		back(count + 1, j + 1, product * v[j]);
	}
}

int main()
{
	freopen("dezastru.in", "r", stdin);
	freopen("dezastru.out", "w", stdout);

	scanf("%d%d", &n, &k);
	for (int i = 0; i < n; i++)
	{
		scanf("%lf", &v[i]);
	}

	back(0, 0, 1.0);

	printf("%0.6lf", (double)((double)sum / (double)num));

	return 0;
}