Loot Chest
InterviewTime limit1sMemory limit1024 MB
Given that the prize chance grows on losses and non-prize wins and resets after any prize, compute the expected matches until a gorilla-suit prize.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Probability, Math
- Solved
- No attempts yet
Problem
Your favorite online game has a prize system. After each match you win, you receive a prize with probability . The value of changes over time as follows:
- Every time you lose a match, increases by .
- Every time you win a match but do not receive a prize, increases by .
- Every time you win a match and receive a prize, is set to .
Whenever increases, it is capped at . That is, if is increased by , then becomes .
The developers have just revealed that one of the prizes this season is a silverback gorilla suit with star-shaped sunglasses. You want it! Each prize is this gorilla suit with probability .
You start with . Each match you play has a chance of being a loss. Given and , compute the expected number of matches you will play until you obtain the silverback gorilla suit.
For example, in the first sample case you win every match and are guaranteed to receive a prize every 2 matches. Each prize is the gorilla suit with probability . So you expect to obtain the gorilla suit after receiving 2 prizes. Thus, in expectation, it takes 4 matches to obtain the gorilla suit.
Input
The input consists of a single line containing four integers (), (), (), and (), which are described above.
Output
Display the expected number of matches you will play before you obtain the gorilla suit. Your answer should have an absolute or relative error of at most .