Cod sursa(job #2922517)

Utilizator raresgherasaRares Gherasa raresgherasa Data 8 septembrie 2022 19:22:19
Problema Dezastru Scor 70
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.73 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 back (int k){
  for (int i = x[k - 1] + 1; i <= n; i++){
    if (k <= m){
      x[k] = i;
      if (k == m){
        double r = 1;
        for (int j = 1; j <= m; j++){
          r *= a[x[j]];
        }
        ans += r;
        ++cnt;
      }
      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(7) << ans / cnt << '\n';
}