Expected Eyes
Time limit4sMemory limit1024 MB
Given n dice and the number of faces on each, print the expected value of the sum when all dice are rolled at once.
- Level
Easy2 of 10
- Topics
- Math
- Solved
- No attempts yet
Problem
Once upon a time, in a small kingdom in the Faraway Province of Combinatorics, a king was obsessed with dice. He owned a collection of multi-faced dice from all over the world, and he loved to play games with them.
One day, the king came up with a new game. Every player chooses a number, and then the king rolls all his dice at once. The player whose choice is closest to the sum of the dice wins. The king hates losing, so he decided to always choose the expected value of his throw. He is not very good at mathematics, so he asked you to solve this problem.
Given the list of dice and the number of faces on each one, calculate the expected value of throwing all of them at once.
The expected value of an event is the weighted average of all possible outcomes.
Consider two dice, one with 3 faces and one with 2 faces. The possible sums are:
- 2 from (1, 1)
- 3 from (1, 2) or (2, 1)
- 4 from (2, 2) or (3, 1)
- 5 from (3, 2)
Add up all the outcomes and divide by the total number of equally likely throws.
Input
The first line contains an integer (), the number of dice.
The second line contains integers (), the number of faces on each die.
Output
Print the expected value of throwing all the dice. Your answer is accepted if its absolute or relative error is at most .