Cod sursa(job #1675142)

Utilizator DeehoroEjkoliPop Darian DeehoroEjkoli Data 5 aprilie 2016 09:32:46
Problema Dezastru Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.93 kb
#include <fstream>
#include <iomanip>
using namespace std;
ifstream fin("dezastru.in");
ofstream fout("dezastru.out");

short n, k;

int numbering;

double attack[30], result = 1, total;

bool was_here[30];

void back_track(short position) {
    for (short i = 1; i <= n; ++i) {
        bool enter = false;
        if (was_here[i] == false) {
            enter = true;
            was_here[i] = true;
            result *= attack[i];
            if (position != k)
                back_track(position + 1);
            else {
                total += result;
                ++numbering;
            }
        }
        if (enter) {
            result /= attack[i];
            was_here[i] = false;
        }
    }
}

int main()
{
    fin >> n >> k;
    for (short i = 1; i <= n; ++i)
        fin >> attack[i];
    back_track(1);
    fout << fixed << setprecision(6) << total / numbering;
    return 0;
}