Cod sursa(job #1694041)

Utilizator VladTiberiuMihailescu Vlad Tiberiu VladTiberiu Data 24 aprilie 2016 16:36:02
Problema Dezastru Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.88 kb
#include <bits/stdc++.h>

#define NMax 26
using namespace std;
ifstream f("dezastru.in");
ofstream g("dezastru.out");

float fol[NMax],a[NMax];
int st[NMax];
float ANS;
int n,k,w,total;

void afisare(int k){
    float p = 1;
    for(int i = 1; i <= k; ++i){
        p *= a[st[i]];
    }

    ANS = ANS + ((float)p / (float)total);
  //  g << '\n';
}
void back(int k){
    for(int i = 1; i <= n; ++i){
        if(!fol[i]){
            fol[i] = 1;

            st[k] = i;

                if(k == w)
                    afisare(k);
                back(k + 1);

            fol[i] = 0;
        }
    }
}
int main()
{
    f >> n >> w;
    for(int i = 1; i <= n; ++i){
        f >> a[i];
    }
    total = 1;
    for(int i = n - w + 1; i <= n; ++i){
        total *= i;
    }
    back(1);
    g << fixed << setprecision(8) << ANS << '\n';
    return 0;
}