Problem Statement
Each move looks as follows: You choose one of the four cardinal directions (up, down, left, or right) uniformly at random, and you move the token one cell in the chosen direction.
You are given the
Let E be the expected value of your score. Compute and return the following value: (E * 4^t) modulo 1,000,000,007.
Definition
- Class:
- RandomWalkOnGrid
- Method:
- getExpectation
- Parameters:
- int, int, int, int, int
- Returns:
- int
- Method signature:
- int getExpectation(int x0, int y0, int t, int n, int m)
- (be sure your method is public)
Constraints
- x0 and y0 will be between -1,000,000,000 and 1,000,000,000, inclusive.
- t will be between 0 and 1,000,000,000, inclusive.
- n and m will be between 1 and 100, inclusive.
Examples
2
2
1
1
1
Returns: 16
The token starts in the cell (2, 2). As t=1, you move it exactly once. Hence, with equal probability the token will end in one of the following four cells: (1, 2), (2, 1), (2, 3), and (3,2). The scores for these cells are 2, 2, 6, and 6. Thus, the expected score is E = (2+2+6+6)/4 = 4. This means that you should return the value (4 * 4^1) modulo 1,000,000,007 = 16.
2
2
2
1
1
Returns: 64
1
2
3
1
2
Returns: 352
123456
1654321
20
20
20
Returns: 860242008
0
0
1000000000
1
10
Returns: 0
-887550029
-425167655
93615980
99
53
Returns: 386681114
-427580039
-768715515
900336294
5
49
Returns: 876992936
151485118
207570246
356694563
44
7
Returns: 940283739
-657127604
-709966314
362083632
72
43
Returns: 492048133
506867352
-473515706
175854056
1
56
Returns: 882364172
661267549
-811851455
943422141
77
49
Returns: 103539425
-1000000000
-1000000000
200000000
1
1
Returns: 947675421
-780877811
944328809
1000000000
100
100
Returns: 390687226
-905752410
-800789620
1000000000
100
100
Returns: 907700571
432668310
-694681361
1000000000
100
100
Returns: 586013186
-728880840
696666363
1000000000
100
100
Returns: 49540967
946925817
-954396094
1000000000
100
100
Returns: 622917465
-373361022
956680906
1000000000
100
100
Returns: 68791639
-75212831
231384488
1000000000
100
100
Returns: 588564196
2453452
129029
1000000000
100
100
Returns: 112925438
-1000000000
-1000000000
1000000000
1
1
Returns: 623291020
2349023
2349082
1000000000
100
100
Returns: 949235123