ARAM (Small)
Time limit5sMemory limit512 MB
Decide when to spend a capped, regenerating reroll budget on fresh random champions to maximize the long-run share of games won.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Probability, Greedy
- Solved
- No attempts yet
Problem
League of Legends has a mode called "ARAM", short for "All Random, All Mid". This problem borrows the idea, and you do not need to have played the game to follow it.
Every time you start a game you are assigned one of champions uniformly at random. You win more often with some champions than with others, so an unlucky assignment leaves you wishing for a different one. The game has a reroll function for exactly that.
Rerolling works like a kind of money. Before your first game you start with RD (reroll dollars). You can reroll only while you hold at least 1 RD, and each reroll costs 1 RD. After every game you gain RD, where is an integer, but your balance never rises above : if you hold RD and play a game, you still hold RD when that game ends.
If you hold at least 1 RD and choose to reroll, you spend 1 RD and are assigned one of the champions uniformly at random again. The champion you already had can come up again. If you dislike the new champion and still hold at least 1 RD, you reroll again. You can keep rerolling as long as you hold at least 1 RD.
For example, take and . If you use one reroll in your first game, your balance is 1.5 RD when that game ends. Play another game without rerolling and the balance becomes 2.0 RD. Play a third game without rerolling and the balance is still 2.0 RD, because it never rises above . Use two rerolls in the next game and the balance is 0.5 RD when that game ends.
You are given the list of champions and the probability that you win a game played with each of them. If you play games and choose your strategy optimally, what fraction of the games do you expect to win?
Input
The first line contains the number of test cases . Each test case starts with a line holding three space separated integers , and . The next line holds space separated real numbers , where is the probability that you win a game played with champion .
, , , . Every is written with exactly four digits after the decimal point and satisfies .
Output
For each test case print one line of the form "Case #x: y", where is the test case number starting from 1 and is the fraction of the games you win under an optimal strategy. Round to nine digits after the decimal point and print all nine of them.
Note
League of Legends is a trademark of Riot Games. Riot Games has no involvement with this problem.