Risk
Time limit2sMemory limit256 MB
Compute the attacker win probability in a Risk battle with D-sided dice where the defender picks one or two dice after seeing the attack roll.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Probability, Game theory, Combinatorics
- Solved
- No attempts yet
Problem
Vladimir and Mark play the strategy board game Risk. Players occupy regions of the world and try to conquer whole continents. Mark holds a region with armies and wants to attack an adjacent region that Vladimir holds with armies. Mark is the weaker player, so he asks you for the probability that he wins that battle.
The battle follows the standard Risk rules, with one change: the dice do not have to be six sided. Every die has sides with , the sides carry different values, and each side comes up with the same probability.
A battle is a sequence of rounds. Suppose the attacker has armies in the region he attacks from and the defender has armies in his region. One round runs like this.
- The attacker rolls dice. He uses three dice when he can, but one army has to stay in the region and takes no part in the attack, so for he rolls dice.
- The defender looks at the attacker's dice and then rolls. If he rolls one die. If he rolls one or two dice, and he picks the count that makes his own probability of winning the whole battle as large as possible.
- Let be the smaller of the two dice counts. The highest die of each player is compared, and when the second highest die of each player is compared as well. In every comparison the larger value wins, and the defender wins a tie. The loser of a comparison removes one army from his region. Any extra dice are ignored.
The battle ends when the attacker has only one army left, and then the defender has won, or when the defender has no army left, and then the attacker has won.
For example, the attacker rolls three dice showing 4, 2 and 1 while the defender rolls two dice showing 3 and 2. The first comparison is 4 against 3, which the attacker wins. The second comparison is 2 against 2, which the defender wins. Both players lose one army. For another example, if the two highest dice of the attacker both show the largest value , the defender is better off rolling a single die, because then he loses at most one army.
Vladimir knows the rules and the dice, and he defends so that Mark's probability of winning the battle is as small as possible.
Input
The first line contains an integer , the number of test cases. Each test case is given on two lines.
- One line with an integer (), the number of sides of the dice.
- One line with two space separated integers and (, ), the number of armies in Mark's region and the number of armies in Vladimir's region.
Output
For each test case print one line with the probability that Mark wins the battle, rounded to exactly six digits after the decimal point. Do not use scientific notation.