Cod sursa(job #1552802)

Utilizator VladTiberiuMihailescu Vlad Tiberiu VladTiberiu Data 18 decembrie 2015 17:59:50
Problema Dezastru Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.98 kb
#include <cstdio>
#define L 27
using namespace std;

int aranjamente(int n,int k);

int st[L],fol[L];
float a[L];
float raspuns;
int n,w,aranj;

void afisare(int k){
    float total = 1;
    for(int i = 1; i <= k; i++){
        total *= a[st[i]];
    }
    raspuns += (total/aranj*w);
}
void back(int k){
    for(int i = st[k - 1] + 1; i <= n; i++){
        if(fol[i] == 0){
            fol[i] = 1;

            st[k] = i;
            if(k == w)
                afisare(k);
            else
                back(k + 1);

            fol[i] = 0;
        }
    }
}
int main()
{
    freopen("dezastru.in","r",stdin);
    freopen("dezastru.out","w",stdout);
    scanf("%d %d",&n,&w);
    for(int i = 1; i <= n; i++){
        scanf("%f",&a[i]);
    }
    aranj = aranjamente(n,w);
    back(1);
    printf("%f",raspuns);
    return 0;
}
int aranjamente(int n,int k){
    int rez = 1;
    for(int i = k; i <= n; i++){
        rez *= i;
    }
    return rez;
}