ZombieRPGDice
TCO20 Round 3A · 2020-04-13 · by misof
Problem Statement
This problem has a non-standard time limit: 4 seconds.
This problem is about a specific way of rolling the dice in one franchise of tabletop RPG games.
Whenever the player attempts a non-trivial action, the action is evaluated as follows:
- The game master sets the target value T based on the player's skill.
- The game master gives the player some 6-sided dice to roll. Each die is either positive or negative.
- The player rolls all the dice.
- As long as there is a positive and a negative die with the same value, a pair of such dice is removed from the roll.
- At this point, if there is a positive die with value less than or equal to the target, the roll is a success, otherwise it is a failure.
- Each negative die that was not removed counts as a point of stress for the player. In this problem the points of stress do not matter and can be ignored.
For example, suppose the player had the target T = 5 and rolled P = 4 positive and N = 6 negative dice, getting the values {3, 6, 3, 6} on the positive dice and the values {2, 3, 1, 6, 3, 3} on the negative dice. To evaluate this roll, we first remove several pairs of a positive and a negative die with the same value (value 3 twice and value 6 once). Once we do that, we now see {6} on the only remaining positive die and {2, 1, 3} on the three remaining negative dice. Thus, the roll is a failure and the player receives three points of stress.
You are given the target T, the number P of positive dice and the number N of negative dice. Calculate p: the probability that the roll will be a success. Return (p * 6P+N) modulo 1,000,000,007.
Notes
- It should be obvious that the value (p * 6P+N) is always a non-negative integer, and thus the return value is well-defined.
Constraints
- T will be between 1 and 6, inclusive.
- P will be between 0 and 250, inclusive.
- N will be between 0 and 250, inclusive.
5 1 0 Returns: 5
There is one positive die and no negative dice, the target is 5. The roll will be a success if we roll anything other than a six. The probability of success is p = 5/6, and thus the correct return value is p*6 = 5.
3 0 7 Returns: 0
With only negative dice there can be no success.
4 1 1 Returns: 20
In order to be successful, we need to roll 1, 2, 3, or 4 on the positive die, and we need the negative die to differ from the positive die. The probability that both things happen is p = (4/6) * (5/6) = 20/36.
6 15 0 Returns: 184981286
Remember to use modular arithmetic. The return value shown here is 6^15 modulo (10^9 + 7).
5 4 6 Returns: 50489560
3 0 0 Returns: 0
No dice at all = no success.
Submissions are judged against all 123 archived test cases, of which 6 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class ZombieRPGDice with a public method int expectation(int T, int P, int N) · 123 test cases · 2 s / 256 MB per case