Cod sursa(job #1692237)

Utilizator krityxAdrian Buzea krityx Data 20 aprilie 2016 15:16:08
Problema Dezastru Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.72 kb
#include <fstream>
#include <vector>
#include <list>
#include <iomanip>
using namespace std;

double sum = 0;
int num = 0;

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

int main()
{
	ifstream in("dezastru.in");
	ofstream out("dezastru.out");

	int n, k;
	double x;
	vector<double> v;
	

	in >> n >> k;
	for (int i = 0; i < n; i++)
	{
		in >> x;
		v.push_back(x);
	}

	back(0, 0, n, k, v, 1.0);

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

	return 0;
}