Cod sursa(job #2727666)

Utilizator theo2003Theodor Negrescu theo2003 Data 22 martie 2021 12:10:10
Problema Dezastru Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.66 kb
#include <fstream>
#include <algorithm>
#include <iomanip>
using namespace std;
ifstream cin("dezastru.in");
ofstream cout("dezastru.out");
int n, k;
long double total = 0, a[25];
int nr = 0;
void select(int x, int y, long double p = 1){
    if(y > (n - x))
        exit(1);
    p *= a[x];
    if(y == 0){
        total += p;
        nr++;
        return;
    }
    for(int z = x + 1;z<(n - y + 1);z++){
        select(z, y - 1, p);
    }
}
int main(){
    cin>>n>>k;
    for(int x = 0;x<n;x++)
        cin>>a[x];
    for(int x = 0;x<(n - k + 1);x++){
        select(x, k - 1);
    }
    cout<<setprecision(100)<<total/nr<<'\n';
    return 0;
}