Cod sursa(job #2090985)

Utilizator Teodor.mTeodor Marchitan Teodor.m Data 18 decembrie 2017 22:29:09
Problema Dezastru Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.79 kb
#include <bits/stdc++.h>

using namespace std;

const double eps = 0.000001;
int x[30], n, p, nr;
double a[30], prob;

void calcul()
{
	double prod = 1.0;
	for(int i = 1; i <= p; ++i)
		prod *= a[x[i]];

	prob += prod;
	nr++;
}

bool valid(int k)
{
	for(int i = 1; i < k; ++i)
		if(abs(x[i] - x[k]) < eps)
			return false;
	return true;
}

void solve()
{
	int k = 1;
	while(k > 0) {
		while(x[k] < n) {
			x[k]++;

			if(valid(k))
				if(k == p)
					calcul();
				else {
					k++;
					x[k] = 0;
				}
		}
		k--;
	}
}

int main()
{
	freopen("dezastru.in", "r", stdin);
	freopen("dezastru.out", "w", stdout);
	ios::sync_with_stdio(NULL);
	cin.tie(0);cout.tie(0);


	scanf("%d %d", &n, &p);

	for(int i = 1; i <= n; ++i)
		scanf("%lf", &a[i]);

	solve();
	printf("%lf", prob / (double)nr);

	return 0;
}