Chocolate Wholesaler
Time limit1sMemory limit128 MB
Given n independent bars with individual surprise probabilities, find the probability that a carton has at least k surprises.
- Level
Medium5 of 10
- Topics
- Probability, Dynamic programming
- Solved
- No attempts yet
Problem
A chocolate company is running a promotion: some chocolate bars hide a surprise inside, but you cannot tell from the outside whether a given bar contains one.
Fortunately, you can analyze each bar and determine the probability that it contains a surprise. Chocolates arrive at the wholesaler in cartons of bars, and you may only buy a whole carton, never a single bar.
Buying a carton pays off only if it contains at least surprises. Assuming the surprises occur independently across bars, compute the probability that a carton of chocolates contains at least surprises.
Input
The first line contains the number of test cases .
For each test case, the first line contains two integers and . The second line contains real numbers giving the probability that each chocolate contains a surprise; every probability is given to four decimal places.
Output
For each test case, print on its own line the probability that a carton of chocolates contains at least surprises. Round the result to four decimal places.