Cod sursa(job #2635091)

Utilizator alex.prohnitchiAlex Prohnitchi alex.prohnitchi Data 13 iulie 2020 11:45:02
Problema Dezastru Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.95 kb
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

typedef long long ll;

const ll mod=1e9+7;

const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int maxn=1e7+5;

#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define rc(x)  return cout<<x<<"\n",0
#define sz(s)  (int) s.size()
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;
double rasp=0;
ll t,s[28],cnt,n,k;
double prob[maxn];
vector<double>ans;
	

void perm(int p, int ind, double s) {
	if (ind <= n && p == k) {
		cnt++;
		rasp+=s;
		return;
	}
	else {
		for (int i=ind+1; i<=n; i++) {
			perm(p+1,i,s*prob[i]);
		}
	}
}

int main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ifstream cin("dezastru.in");
	ofstream cout("dezastru.out");
	cin >> n >> k;
	for (int i=1; i<=n; i++) {
		cin >> prob[i];
	}
	perm(0,0,1);
	rasp/=cnt;
	cout << rasp << '\n';
}