Breaking Windows (Large)
Time limit30sMemory limit512 MB
Compute the chance that random stone throws break at least one of K windows after random reinforcements raise their durability.
- Level
Medium7 of 10
- Topics
- Probability, Combinatorics, Dynamic programming
- Solved
- No attempts yet
Problem
A room is surrounded by windows. A window breaks when a stone hits it. of the windows are reinforced, so each of them survives the first stone and breaks on the second one. The other windows are not reinforced, so each of them breaks on the first stone.
villains hold a meeting in this room. To mark the occasion, each villain picks one window and throws one stone at it. Each villain picks the target uniformly at random among the windows, independently of everyone else. A stone thrown at a window that is already broken passes straight through it.
You own the room, so you hire workers to reinforce the windows before the meeting. Each worker also picks one window uniformly at random among the windows, independently of everyone else, and reinforces it. Every reinforcement lets that window survive one more stone.
Compute the probability that at least one window is broken after the meeting.
Input
The first line contains the number of test cases . Each of the next lines contains four integers , , , separated by spaces.
Constraints
Output
For each test case, print one line in the form Case #x: y, where is the case number starting from 1 and is the probability that at least one window is broken. Round to eight digits after the decimal point and always print all eight digits.
Notes
All three cases in the sample input use a room with three windows.
In the first case the windows stay intact only when the worker reinforces the same window that the stone hits, so the probability of a break is .
In the second case, even if a reinforced window survives one stone, no window can survive the other stone, so the probability is .
In the third case the two reinforced windows cannot break. The remaining window breaks only when neither of the two workers reinforces it and the stone hits it, so the probability is .