



(X is the Knight’s current position, O is the position Knight can visit in 1 move)
Print output up to 6 decimal places.
The first line of the input contains ‘T’ denoting the number of test cases.
In the first line of each test case take two space-separated integers, ‘N’ and ‘K’ denoting the dimension of the chessboard and the number of moves played by the knight.
In the second line of each test case take two space-separated integers, ‘Sx’ and ‘Sy’ denoting the initial position of the knight in the chessboard.
For each test case print the probability in the new line.
Print output up to 6 decimal places. Print the output for each test case in a separate line.
1 <= T <= 5
0 <= N <= 30
0 <= K <= 500
0 <= Sx, Sy <= N - 1
(Sx, Sy) being the initial coordinates of the knight.
Time Limit: 1 sec
Explanation:
i.e.
P(i, j, k)= [ P(i + 2, j + 1, k - 1) + P(i + 2, j - 1, k - 1) + P(i - 2, j + 1, k - 1) + P(i - 2, j - 1, k - 1) + P(i + 1, j + 2, k - 1) + P(i + 1, j - 2, k - 1) P(i - 1, j + 2, k - 1) + P(i - 1, j - 2, k - 1) ] / 8
Where P(i, j, k) is the probability of remaining inside the chessboard when at position (i, j) and we have to make ‘k’ moves.
Algorithm:
We just use memoization in the previous approach. After checking if k is 0 or not. We check if the current positions (i, j) and remaining steps k, are already calculated. If they are already calculated then we return the answer. Else we solve it using the above approach and cache it in the end.