Robot
Time limit1sMemory limit512 MB
Compute the expected squared distance from the origin after a robot takes N probabilistic left, straight, or right moves, and print it as a fraction modulo 1e9+7.
- Level
Medium6 of 10
- Topics
- Probability, Math, Dynamic programming
- Solved
- No attempts yet
Problem
A robot stands at the origin of the xy plane. It faces the positive x direction, and from now on it makes moves. One move works like this.
- The robot turns 90 degrees to the left of its facing with probability , keeps its facing with probability , and turns 90 degrees to the right of its facing with probability . From the starting state, a left turn makes it face the positive y direction and a right turn makes it face the negative y direction.
- Once the facing is settled, the robot moves a distance of 1 in that direction.
If the robot ends up at after moves, how far it sits from the origin is measured by . Write a program that computes the expected value of that measure after the robot makes moves.
Input
The first line contains four integers , , , separated by spaces. is the number of moves the robot makes, and , , determine the probability of turning left, of keeping the facing, and of turning right. At least one of , , is a positive integer. (, )
Output
Print the expected value of how far the robot sits from the origin after moves. For exact judging, write the answer as a reduced fraction and print the remainder of divided by 1,000,000,007 instead. Here is the multiplicative inverse of modulo 1,000,000,007. The answer exists for every input that can be given in this problem.