Cod sursa(job #2493429)

Utilizator ralucaantonAnton Raluca ralucaanton Data 16 noiembrie 2019 12:15:45
Problema Dezastru Scor 60
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("dezastru.in");
ofstream fout("dezastru.out");
int st[30], n, k;
double s, v[30];
unsigned long long nr;

void solutie()
{
    double x=1;
    for(int i=1; i<=k; i++)
    {
        x=x*v[st[i]];
    }
    s=s+x;
}

void bkt(int niv)
{
    int i;
    for(i=st[niv-1]+1; i<=n; i++)
    {
        st[niv]=i;
        if(niv==k)
        {
            solutie();
            nr++;
        }
        else
            bkt(niv+1);
    }
}

int main()
{
    fin>>n>>k;
    for(int i=1; i<=n; i++)
    {
        fin>>v[i];
    }
    bkt(1);
    fout<<s/nr;
    fin.close();
    fout.close();
    return 0;
}