Ability
Time limit2sMemory limit512 MB
Compute the expected damage of one attack where abilities are tried in a uniformly random order without replacement until one fires, and output the fraction modulo 1e9+7.
- Level
Medium7 of 10
- Topics
- Probability, Math, Combinatorics, Dynamic programming
- Solved
- No attempts yet
Problem
A player fights monsters in a web game and has all attack abilities equipped at once. The abilities are numbered 1 through .
Ability has a trigger probability and a damage value . When the player issues a trigger command to ability , the ability fires with probability and deals damage to the opponent, and with probability it does not fire and nothing happens.
One attack opportunity runs like this.
- Choose one of the equipped abilities. Every ability is equally likely to be chosen.
- Issue a trigger command to the chosen ability.
- If the ability fires, the attack opportunity is spent and the process ends.
- If it does not fire, choose one of the abilities that has not received a command yet, again with equal probability, then go back to step 2.
- If every ability has received a command and none of them fired, the attack opportunity is spent with no damage.
Given the trigger probability and the damage of all abilities, compute the expected damage dealt in one attack opportunity.
Input
The first line contains the number of abilities ().
Line of the next lines contains two integers and () separated by a space. Ability fires with probability and deals damage when it fires.
Output
Print the expected damage dealt in one attack opportunity. Write the expected value as an irreducible fraction and print instead, where is the multiplicative inverse of modulo . This value exists for every input given in this problem.