Problem Statement | |||||||||||||
There are some cards in a box which are specified by a String[] cards. One of the operators '+', '-' or '*' is written on the left half of each card and a digit is written on the right half of each card. You draw all cards from the box randomly, one by one. At each step each of the remaining cards has the same probability of being drawn. Then you align the cards from left to right in the order you have drawn them. Finally, add a zero at the left of the cards and calculate the value of this expression. For example, if you have drawn "+1", "-2" and "*3" (in this order), the expression is "0 + 1 - 2 * 3", whose value is -5. Return the expected value. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Notes | |||||||||||||
- | The returned value must have an absolute or relative error less than 1e-9. | ||||||||||||
Constraints | |||||||||||||
- | cards will contain between 1 and 50 elements, inclusive. | ||||||||||||
- | Each element of cards will contain exactly 2 characters. | ||||||||||||
- | The first character in each element of cards will be either '+', '-' or '*'. | ||||||||||||
- | The second character in each element of cards will be a digit ('0' - '9'). | ||||||||||||
Examples | |||||||||||||
0) | |||||||||||||
| |||||||||||||
1) | |||||||||||||
| |||||||||||||
2) | |||||||||||||
| |||||||||||||
3) | |||||||||||||
| |||||||||||||
4) | |||||||||||||
| |||||||||||||
5) | |||||||||||||
|