Problem Statement | |||||||||||||
You have a deck that contains R red and B black cards. You are playing the following game: You shuffle the deck, and then begin dealing the cards one by one. For each red card you flip you get a dollar, and for each black card you flip you have to pay a dollar. At any moment (including the beginning of the game) you are allowed to stop and keep the money you have. Write a method that will take the ints R and B, and return the expected amount you will gain if you play this game optimally. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Notes | |||||||||||||
| - | During the game, your balance may be negative. | ||||||||||||
| - | We assume that each permutation of the cards in the deck is equally likely. | ||||||||||||
| - | Your return value must have a relative or absolute error less than 1e-9. | ||||||||||||
Constraints | |||||||||||||
| - | R will be between 0 and 5,000, inclusive. | ||||||||||||
| - | B will be between 0 and 5,000, inclusive. | ||||||||||||
Examples | |||||||||||||
| 0) | |||||||||||||
| |||||||||||||
| 1) | |||||||||||||
| |||||||||||||
| 2) | |||||||||||||
| |||||||||||||
| 3) | |||||||||||||
| |||||||||||||
| 4) | |||||||||||||
| |||||||||||||
| 5) | |||||||||||||
| |||||||||||||