Cod sursa(job #1771616)

Utilizator giotoPopescu Ioan gioto Data 5 octombrie 2016 20:14:30
Problema Dezastru Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.6 kb
#include <cstdio>
using namespace std;

int n, k, NR;
float a[27];
double Sol;
bool f[27];
inline void back(int Last, int j,double p){
    if(j == k){
        Sol = Sol + p;
        ++NR; return ;
    }
    int m = n - (k - j) + 1;
    for(int i = Last + 1; i <= m; ++i)
        back(i,j + 1,p * a[i]);
}
int main()
{
    freopen("dezastru.in", "r", stdin);
    freopen("dezastru.out", "w", stdout);
    scanf("%d%d", &n, &k);
    for(int i = 1; i <= n; ++i)
        scanf("%f", &a[i]);
    back(0,0,1);
    Sol = (float)((float)Sol / (float)NR);
    printf("%f", Sol);
    return 0;
}