Cod sursa(job #2728843)
Utilizator | Bogdan Gavra gavra_bogdan | Data | 23 martie 2021 19:26:53 |
---|---|---|---|
Problema | Dezastru | Scor | 80 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.47 kb |
#include <fstream>
#include <iomanip>
#define ld long double
ld ans, v[30], n, k, cnt = 0;
void calc(int curr, ld prob, int kk = 0) {
if(kk==k) {
ans += prob, ++cnt;
return;
}
for(int nxt=curr;nxt<=n-k+kk;nxt++)
calc(nxt+1, prob*v[nxt], kk+1);
}
int main() {
std::ifstream fin("dezastru.in");
std::ofstream fout("dezastru.out");
fin>>n>>k;
for(int i=0;i<n;i++) fin>>v[i];
calc(0, 1.0);
fout<<std::fixed<<std::setprecision(6)<<ans/(ld)cnt;
}