Cod sursa(job #2542800)

Utilizator Florinos123Gaina Florin Florinos123 Data 10 februarie 2020 16:43:13
Problema Dezastru Scor 80
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.62 kb
#include <fstream>

using namespace std;

ifstream f ("dezastru.in");
ofstream g ("dezastru.out");

int n, k, i, nr, sol[30];
double rez, v[30];

void adauga ()
{
 double aux = 1;
 int i;
  for (i=1; i<=k; i++)
        aux *= v[sol[i]];
  rez += aux;
}

void bkt (int poz)
{
   for (int i=sol[poz-1]+1; i<=n; i++)
   {
       sol[poz] = i;
        if (poz == k)
        {
            nr ++;
            adauga();
        }
        else
            bkt(poz+1);
   }
}

int main()
{
  f >> n >> k;
   for (i=1; i<=n; i++)
      f >> v[i];
  bkt(1);
  rez /= nr;
  g << rez;
    return 0;
}