Cod sursa(job #2922516)

Utilizator raresgherasaRares Gherasa raresgherasa Data 8 septembrie 2022 19:20:52
Problema Dezastru Scor 80
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.75 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin ("dezastru.in");
ofstream fout ("dezastru.out");

const int NM = 27;

int n, m, x[NM];
double ans, cnt, p, a[NM], q = 1;

void solve (){
  long double r = 1;
  for (int i = 1; i <= m; i++){
    r *= a[x[i]];
  }
  ans += r;
}

void back (int k){
  for (int i = x[k - 1] + 1; i <= n; i++){
    if (k <= m){
      x[k] = i;
      if (k == m){
        solve();
        cnt += 1;
      }
      else{
        back(k + 1);
      }
    }
  }
}

int main(){
  ios_base::sync_with_stdio(false);
  fin.tie(0);
  fout.tie(0);
  fin >> n >> m;
  for (int i = 1; i <= n; i++){
    fin >> a[i];
  }
  back(1);
  fout << fixed << setprecision(10) << ans / cnt << '\n';
}