Cod sursa(job #1015495)

Utilizator florin.elfusFlorin Elfus florin.elfus Data 24 octombrie 2013 19:06:35
Problema Dezastru Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.88 kb
#include <fstream>
#include <iomanip>

using namespace std;

void Back();


int N, K;
double V[26], final;
int number;

double now;
int k, last;

int main()
{
    ifstream fin("dezastru.in");
    ofstream fout("dezastru.out");

    fin >> N >> K;
    for (int i = 1; i <= N; ++i)
        fin >> V[i];

    now = 1, k = 1, last = 0;
    Back();

    final /= number;
    fout << fixed << setprecision(7) << final;

    fin.close();
    fout.close();
}

void Back()
{
    for (int i = last + 1; i <= N - (K - k); ++i)
    {
        int aux1 = last;
        double aux2 = now;

        if (k < K)
        {
            ++k, now *= V[i], last = i;
            Back();
            --k, now = aux2, last = aux1;
        }
        else
        {
            now *= V[i];
            ++number, final += now;
            now = aux2;
        }
    }
}