Cod sursa(job #2776580)

Utilizator AACthAirinei Andrei Cristian AACth Data 20 septembrie 2021 11:24:18
Problema Dezastru Scor 70
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.11 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;
double a[Max];
int prod;
void read()
{
	prod = 1;
	f>>n>>k;
	int i;
	for(i=1;i<=n;i++)
	{
		f>>a[i];
	}
}
vector<  double > prob;
vector < int > choose;
 double choose_product = 1;
long double ans = 0;
 int cnt = 0;

void generate_bkt(int current)
{
	if(current == k + 1)
	{
		ans += choose_product;
		cnt++;
		return;
	}
	 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);
    ans /= cnt;
    cout<<fixed<<setprecision(10)<<ans<<'\n';
}
void restart()
{

}
int32_t main()
{
    nos();

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