Cod sursa(job #1692267)

Utilizator krityxAdrian Buzea krityx Data 20 aprilie 2016 16:30:51
Problema Dezastru Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.64 kb
#include <fstream>
#include <iomanip>
#include <iostream>

using namespace std;

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

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()
{

	
	ifstream in("dezastru.in");
	ofstream out("dezastru.out");
	ios_base::sync_with_stdio(false);
	in.tie(nullptr);

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

	back(0, 0, 1.0);

	out << setprecision(7) << sum / num;

	return 0;
}