Breaking Windows (Small)
Time limit5sMemory limit512 MB
M workers randomly reinforce K windows and N villains randomly throw one stone each, and the task asks for the probability that at least one window breaks.
- Level
Medium7 of 10
- Topics
- Probability, Combinatorics, Dynamic programming
- Solved
- No attempts yet
Problem
A room is surrounded by windows. A window breaks when it takes enough stones. of the windows are already reinforced, so each of them survives the first stone and breaks on the second one. The other windows are not reinforced and break on the first stone.
Before the meeting the owner of the room hires workers to reinforce the windows further. Each worker picks one window and reinforces it once, and every reinforcement lets that window survive one more stone. A worker's choice is independent of the other workers, and each of the windows is equally likely.
Once the reinforcement is done, villains gather in the room and each of them picks one window and throws one stone at it. A villain's choice is independent of the other villains, and each of the windows is equally likely. A stone thrown at a window that is already broken passes straight through it.
Compute the probability that at least one window is broken after all the stones have been thrown.
Input
The first line contains the number of test cases . Each of the next lines holds one test case as four integers.
K N M H
Constraints
Output
For each test case print one line in the form Case #x: y. Here is the test case number starting from 1, and is the probability that at least one window is broken, rounded to eight decimal places. Always print exactly eight digits after the decimal point, so a value of 0 or 1 is written as 0.00000000 or 1.00000000.
Hint
All three cases in the example use a room with three windows.
In the first case, , , , , the room survives only when the villain throws at the window the worker reinforced, so the probability of a break is .
In the second case, , , , , one window may be reinforced and survive the first stone, but no window survives a second stone. The probability is .
In the third case, , , , , the two pre-reinforced windows cannot break to a single stone. The remaining window breaks when neither worker picks it and the stone hits it, so the probability is .