Cod sursa(job #3310781)

Utilizator nopreanOprean Natasha noprean Data 16 septembrie 2025 20:58:32
Problema Dezastru Scor 60
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.02 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("dezastru.in");
ofstream fout("dezastru.out");
int n,k;
double A[30];
double V[30];
double rez=0.0;
int nrComb=0;
double prod=1.0;
bool OK(int nivel)
{
    if(nivel==1)
        return true;
    if(V[nivel]>V[nivel-1])
        return true;
    return false;
}
bool Solutie(int nivel)
{
    if(nivel==k)
        return true;
    return false;
}
void Afisare()
{
    /*double prod=1.0;
    for(int i=1; i<=k; i++)
        prod*=V[i];*/
    rez+=prod;
    nrComb++;
}
void Back(int nivel)
{
    for(int i=1; i<=n; i++)
    {
        V[nivel]=A[i];
        prod*=V[nivel];
        if(OK(nivel)==true)
        {
            if(Solutie(nivel)==true)
                Afisare();
            else
                Back(nivel+1);
        }
        prod/=V[nivel];
    }
}
int main()
{
    fin>>n>>k;
    for(int i=1; i<=n; i++)
        fin>>A[i];
    Back(1);
    fout<<fixed<<setprecision(6)<<1.0*rez/(nrComb*1.0);
    return 0;
}