Cod sursa(job #2827395)

Utilizator PatrickvasileSoltan Cristian Patrickvasile Data 5 ianuarie 2022 18:04:15
Problema Dezastru Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.46 kb
#include <bits/stdc++.h>
#define fri(a, b) for (int i = (a); i < (b); ++i)
#define frj(a, b) for(int j = a; j < b; j++)
#define frm(a, b, i) for(int i = b; i >= a; i--)
#define ll long long
#define all(x) x.begin(), x.end()
#define mod 1000000007
#define pb push_back
#define fi first
#define se second
#define sz size()
#define rall(x) x.rbegin(), x.rend()
#define cts(x) cout << x << ' '
#define ctn(x) cout << x << '\n'
using namespace std;
 
// string __fname = "dezastru"; ifstream in (__fname + ".in"); ofstream out (__fname + ".out"); 
// #define cin in 
// #define cout out
 
 
const int mx = 1000001;

int n, k;
vector<double> a;
vector<ll> x(26);
double b = 0;
ll f = 0;
double sum = 1;

ll fact(int p){
    if(p == 1 || p == 0){                                                                   
        return 1;
    }
    if(x[p] != 0){
        return x[p];
    }
    x[p] = p * fact(p - 1);
    return x[p];
}

void comb(int w, int u){
    if(u == 0){
        b += sum;
        f++;
        return;
    }
    fri(w, n - u + 1){
        sum *= a[i];
        comb(i + 1, u - 1);
        if(a[i]!= 0)
            sum /= a[i];
    }
}


void solve(){
    cin >> n >> k;
    fri(0, n){
        cin >> b;
        a.pb(b);
    }
    if(n == 1){
        ctn(a[0]);
        return;
    }
    b = 0;
    comb(0, k);
    ctn(b / f);


}
 
 
int main()
{   
    ios_base::sync_with_stdio(0); cin.tie(0); setprecision(6);
    // int t;
    // cin >> t;
    // while(t--)
        solve();
}