Blackjack
Time limit4sMemory limit256 MB
With n cards and limits a < b, compute the best chance to end with total > a and at most b in a randomly shuffled blackjack draw where stopping is allowed.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Probability, Combinatorics
- Solved
- No attempts yet
Problem
There is a saying: "If you hesitate, you lose the game; if you are decisive, you die in vain."
Calabash does not want to lose the game, and he does not want to die in vain either. That is not important, though, because he does not have enough money to buy the game.
Fortunately, Roundgod, the banker of a casino, gives him a chance to fulfill his dream. Roundgod promises to buy him the game if he can win one round of Blackjack. Blackjack uses a deck of playing cards, each with some number of points. The game proceeds as follows. Roundgod gives a number and tells Calabash the number of points on each card. Then Calabash starts drawing cards according to this procedure:
- The deck of all cards is shuffled uniformly at random.
- Calabash may repeatedly draw a card from the deck (he immediately learns the number of points on the card after drawing it), or declare at any moment that he stops drawing.
- If, after drawing any card, the total number of points on the cards Calabash has drawn exceeds a limit , he loses immediately.
- Otherwise, after Calabash stops drawing, he wins if and only if the total number of points on the cards he has drawn is greater than .
Calabash wants to know the probability that he wins if he plays optimally, so that he can obtain his favorite game. Help him calculate this probability.
Input
The input consists of two lines. The first line contains three integers , which denote the number of cards in the deck, the number Roundgod gives, and the limit on the total number of points, respectively. The second line contains integers , which denote the numbers of points on the cards. It is guaranteed that .
Output
Output the answer with an absolute error of no more than .