Cod sursa(job #1747537)

Utilizator calin1Serban Calin calin1 Data 25 august 2016 08:14:25
Problema Dezastru Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.89 kb
#include <iostream>
#include <cstdio>
#include <bitset>

using namespace std;

int n,k;

double prob[30];
double tmp[30];

double nr, imp;

bitset <30> viz;

void calc()
{
    double z = 1;

    for(int i = 1 ; i <= k ; ++i)
    {
        z*=tmp[i];
    }

    nr+=z;
    imp++;
}

void back(int x)
{
    if(x > k)
    {
        calc();
        return;
    }

    for(int i = 1 ; i <= n ; ++i)
    {
        if(!viz[i])
        {
            tmp[x] = prob[i];
            viz[i] = true;
            back(x+1);
            viz[i] = false;
        }
    }
}

void citire()
{
    scanf("%d %d\n",&n,&k);
    for(int i = 1 ; i <= n ; ++i)
    {
        scanf("%lf ",&prob[i]);
    }

    back(1);
}

int main()
{
    freopen("dezastru.in","r",stdin);
    freopen("dezastru.out","w",stdout);

    citire();

    printf("%lf",nr/imp);

    return 0;
}