Card Collecting
Time limit2sMemory limit512 MB
Compute the minimum expected time to collect all n cards, choosing when to trade d cards for a chosen card or play for a random pack.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Probability, Math
- Solved
- No attempts yet
Problem
Lately, a variety of free-to-play collectible card games have become popular. These card games usually have a collection of cards that the player wants to collect. The player first receives a starter pack of cards, which is guaranteed to contain no duplicates (they are all distinct). The player can then acquire new cards in two ways:
- Trade any cards the player holds for one card of the player's choice. This is very quick, and in this problem we assume it takes no time.
- Play games for an hour, and win a pack of cards with probability , where is the number of distinct cards the player currently holds. Each card in the pack is chosen independently and uniformly at random from the entire collection of cards, so the pack may contain duplicates.
The advantage of a larger collection is that the player has a higher chance of winning a pack, and so earns random cards more quickly.
Stingy Larry plays card games of this type all the time. Larry just got a copy of such a game, is about to open his starter pack of cards, and wants to complete the full collection of cards. Assuming that Larry manages his collection optimally, what is the shortest expected time to complete the collection?
Input
The first line contains a single integer (), the number of test cases.
The first line of each test case contains four integers , , , and : () is the total number of cards in the collection, () is the number of cards in the starter pack, () is the number of cards in a pack, and () is the number of cards that must be traded for one new card.
The next line contains space-separated real numbers (), where is the probability of winning a pack after an hour of play while holding distinct cards. The are nondecreasing.
Output
For each test case, print on its own line the shortest expected time, in hours, for Larry to complete the collection, rounded to exactly six digits after the decimal point.
Hint
In the first test case of the example, Larry needs to play four hours on average to win the single card he needs to complete his collection.