Cod sursa(job #2399141)

Utilizator Xutzu358Ignat Alex Xutzu358 Data 6 aprilie 2019 22:49:05
Problema Dezastru Scor 60
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.63 kb
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
ifstream f("dezastru.in");
ofstream g("dezastru.out");
double x,v[30],perm[30],prod,sum;
int cif,n,m;
void citire() {
f >> n >> m;
for (int i=1;i<=n;i++) {
    f >> v[i];
}
}
void solutie() {
    prod=1;
    for (int j=1;j<=m;j++) {
        prod*=perm[j];
    }
    cif++;
    sum+=prod;
}
int bkt(int k , int r) {
  if (k==m) {
    solutie();
  }
  else {
  for (int i=r;i<=n;i++) {
        perm[k+1]=v[i];
        bkt (k+1 , i+1);
   }
  }
}
int main()
{
    citire();
    bkt(0 ,1);
  g << setprecision(6) <<sum/cif;
    return 0;
}