ARAM (Large)
Time limit120sMemory limit512 MB
Decide when to spend reroll currency on random champions to maximize the long-run win rate over many games.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Probability, Binary search, Sorting
- Solved
- No attempts yet
Problem
League of Legends™ has a game mode called ARAM, short for All Random, All Mid. This problem uses a simplified version of its rules, so you do not need to have played the game.
Every time you start an ARAM game, one of champions is assigned to you uniformly at random. Your chance of winning depends on the champion, so an unlucky draw leaves you wishing for a different one. The game has a reroll function.
The right to reroll works like money. Before your first game you start with RD (reroll dollars). You can reroll only while you hold at least RD, and each reroll costs RD. After every game you gain RD, where is an integer, but your RD never goes above . If you play a game while holding RD, you still hold RD when that game ends.
While you hold at least RD, choosing to reroll spends RD and assigns you one of the champions uniformly at random again. The champion you already had can come up again. If you dislike the champion you rerolled into and still hold at least RD, you can reroll again. You can keep rerolling as long as you hold at least RD.
For example, take and and suppose you use one reroll in your first game. After that game you hold RD. If you play the next game without rerolling, you hold RD after it. If you play another game without rerolling, you still hold RD, because you cannot go above . If you use two rerolls in the game after that, you hold RD once it ends.
You are given the list of champions and the probability that you win a game played with each of them. Compute the expected fraction of wins when you play games and choose your strategy optimally. The count is large enough that the answer agrees, to nine digits after the decimal point, with the largest long run average of the expected win probability per game.
Input
The first line contains the number of test cases . Then test cases follow. The first line of each test case contains three space separated integers , and . The next line contains space separated real numbers , where is the probability that you win a game played with champion .
Output
For each test case, print one line in the form Case #x: y, where is the test case number starting from and is the expected fraction of games you win over games. Round and print exactly nine digits after the decimal point.
Constraints
- is given as one digit, a decimal point, then four digits.
Note
League of Legends is a trademark of Riot Games. Riot Games does not endorse this problem and has no involvement with it.