#872. MS and the Food Store Ft. Hamburger
MS and the Food Store Ft. Hamburger
Background
MS is a very NB teammate of Legendary Grandmaster DiDiDi, There are endless stories about how they won the championship in various Grand Prix.
One day after they won the championship in GP of Zhijiang, MS went to Zhijiang food street to find what to eat tonight.
Through the traversal of the food street, he found a burger shop that uses robots to automatically add bread and ingredients.
The toppings of the burger include beef, pickled cucumber, etc., a total of . MS likes each ingredient to a different degree, but what is more important is the combination of ingredients, and there are differences between different combinations and orders. Every time the robot adds a random topping to the burger, MS wants to score the existing burger according to his own taste. For example, adding a piece of beef may get points, and adding a pickled cucumber will bring it down to points, but the maximum score will not exceed . MS summed up the rules if the current score is , then basically there will be a probability of becoming , (starting with a score of ), MS wants to know the expected score of a burger with toppings added.
Formally, given a score transition probability matrix, you need to find the expected score after making transitions.
Round your answer to the nearest integer.
Input
The first line contains an integer n, indicating the number of ingredients .
The next n lines, each line has three decimal places, the ith line and the column indicate that the original score is , and after adding an ingredient, there is a probability of to become .
It is guaranteed that the sum of the probabilities of each row is , that is, .
Output
Output a positive integer in the first line, indicating the expected score
Examples
3
0.100 0.100 0.800
0.400 0.500 0.100
0.100 0.400 0.500
2
Note
It can be obtained that after adding ingredients, there is
• a probability of to get points
• a probability of to get points
• a probability of to get points
Therefore the expected score is $1 × 0.212121 + 2 × 0.373737 + 3 × 0.414141 = 2.202018$, rounded to .