Drawing lots
Time limit2sMemory limit512 MB
Compute the expected number of draws until a blue lot has been drawn K times, where red lots are removed and green and blue lots are returned.
- Level
Hard9 of 10
- Topics
- Probability, Math, Dynamic programming
- Solved
- No attempts yet
Problem
He draws lots whenever he has time to spare. Drawing them with no rules attached got boring, so he settled on rules that depend on the color of the lot he draws.
He has lots with a red tip, lots with a green tip, and lots with a blue tip. He puts every lot into a box with the colored end hidden, mixes the box well, and draws one lot at a time. He mixes the box thoroughly every time, so every lot still in the box is equally likely to be drawn. He acts on the color of the lot he drew as follows.
- If he draws a red lot, he throws that lot away.
- If he draws a green lot, he puts it back into the box and mixes the box.
- If he draws a blue lot, he puts it back into the box and mixes the box. Once he has drawn a blue lot times, he stops drawing and goes to sleep.
Write a program that computes the expected number of lots he draws before he goes to sleep.
Input
The first line contains the number of test cases ().
Each test case is one line holding the number of red lots , the number of green lots , the number of blue lots , and the number of blue draws that sends him to sleep, separated by spaces. All four numbers are integers between and .
Output
For each test case, print the expected number of lots he draws before he goes to sleep on its own line.
When the expected value is written as the irreducible fraction , print the remainder of divided by 1,000,000,007. Here is the multiplicative inverse of modulo 1,000,000,007. An answer exists for every input.
Hint
For , , , the expected value is . The inverse of modulo 1,000,000,007 is , so print the remainder of divided by 1,000,000,007, which is .