Cod sursa(job #3262300)

Utilizator stefan_dore_Stefan Dore stefan_dore_ Data 9 decembrie 2024 17:43:07
Problema Dezastru Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.69 kb
#include <fstream>
#include <iomanip>
using namespace std;

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

const int NMAX = 25;
int n, K, x[NMAX+1];
double v[NMAX+1], cnt, prod, sol;

void backTracking(int k) {
    if (k <= K) {
        for (int i = x[k-1]+1; i<=n; i++) {
            x[k] = i;
            prod *= v[i];
            backTracking(k+1);
            prod /= v[i];
        }
    } else {
        cnt ++;
        sol += prod;
    }
}

int main()
{
    f >> n >> K;
    for (int i=1; i<=n; i++)
        f >> v[i];
    prod = 1;
    backTracking(1);
    g << fixed << setprecision(6) << sol / cnt;
    f.close();
    g.close();
    return 0;
}