Cod sursa(job #2542776)

Utilizator Florinos123Gaina Florin Florinos123 Data 10 februarie 2020 16:21:25
Problema Dezastru Scor 60
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.76 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];

bool ok (int poz)
{
 int i;
  for (i=1; i<poz; i++)
     if (sol[i] >= sol[poz])
       return false;
  return true;
}

void bkt (int poz, double produs)
{
   for (int i=1; i<=n; i++)
   {
       sol[poz]= i;
        if (ok(poz))
        {
           double aux = produs * v[sol[poz]];
            if (poz == k)
            {
                nr ++;
                rez += aux;
            }
            else
                bkt(poz+1, aux);
        }
   }
}

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