Cod sursa(job #2776578)

Utilizator AACthAirinei Andrei Cristian AACth Data 20 septembrie 2021 11:20:16
Problema Dezastru Scor 60
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.17 kb
#include <bits/stdc++.h>
using namespace std;
ifstream f("dezastru.in");
ofstream g("dezastru.out");
#define cin f
#define cout g
//#define int long long
const int Max = 26;
void nos()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
int n,k;
long double a[Max];
int prod;
void read()
{
	prod = 1;
	f>>n>>k;
	int i;
	for(i=1;i<=n;i++)
	{
		f>>a[i];
	}
}
vector< long double > prob;
vector < int > choose;
long double choose_product = 1;
void generate_bkt(int current)
{
	if(current == k + 1)
	{
		prob.push_back(choose_product);
		return;
	}
	long double auxchoose = choose_product;
	int start = 1;
	if(!choose.empty())
		start = choose.back() + 1;
	for(int i = start;i<=n;i++)
	{
		choose_product *= a[i];
		choose.push_back(i);
		generate_bkt(current + 1);
		choose.pop_back();
		choose_product = auxchoose;
	}
}
void solve()
{
    generate_bkt(1);
    long double ans = 0;
    int cnt = prob.size();
    for(auto it : prob)
    	ans += it / cnt;
    cout<<fixed<<setprecision(10)<<ans<<'\n';
}
void restart()
{

}
int32_t main()
{
    nos();

        read();
        solve();
        restart();
    
    return 0;
}