A player fights monsters in a web game and has all N attack abilities equipped at once. The abilities are numbered 1 through N.
Ability i has a trigger probability pi and a damage value di. When the player issues a trigger command to ability i, the ability fires with probability pi and deals di damage to the opponent, and with probability 1−pi 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 N abilities, compute the expected damage dealt in one attack opportunity.