Put a given state, now requires with the least amount of steps from (1, 1) to (M, N), and 1 for
Algorithm analysis algorithm is breadth-first search algorithm is easier to think of, as a result of the search tree branches of the tree is 3 fork, very easy to "timeout",
Even with the terms of pruning effect is still not clear,
We analyze the problem: for a piece, its only a total of 24 kinds of state, at point (1, 1), the right back to the point (2, 1),
Roll up to (1, 2), and the state of the arbitrary point (I, J) is the (I - 1, J) and (I, J - 1) state derived,
So, if regulation pawn can up and rolling to the right, you can use the method of dynamic programming will arrive at point (M, N) of all possible
State is derived, and if can only be reached up and back to right (M, N), this method must be the best,
So, we start from (1, 1) to carry on the breadth first search, for each node will be extended out a dynamic programming,
Until the dynamic programming to find the solution, or breadth-first search to find a solution, which can guarantee the optimal solution,
Use simple search to timeout, when M, N is bigger can use dynamic programming
For a piece, a total of 24 kinds of state, at point (1, 1), the right back to the point (2, 1), roll up to the point of (1, 2).
And the state of the arbitrary point (I, J) is the (I - 1, J) and (I, J - 1) damage state is derived, so if the pawn can upward and to the right
Roll, you can use the method of dynamic programming will arrive at point (M, N) of all possible states. Obviously, from (1, 1) to (M, N) these
State of the optimal path, if there is 1 on oriented in these states, have to find the solution. If not, then you can start point (M, N) breadth
Search to (M, N) point state set as the initial state, each extension step, check whether there is the current state of the set of state and to state grid group
In the state of the same, if any, by the dynamic programming of optimality optimality and breadth search can guarantee to find the optimal solution.
CodePudding user response:
First of all, it's not called pieces called dice,1 face, rolling four steps in the direction of X or Y back into 1 face on,
So the first X, Y direction whole four steps away: S1=(((M - 1), 4) + ((N - 1), 4)) * 4
The rest of the distance
M2=(M - 1) Mod 4
N2=(N - 1) Mod 4
Equivalent to o (1, 1) to (M2 + 1, n + 1) solutions, is at most 5 x5 grid, dice 6, 5 * 5 * 6=120 state,
Both in breadth and depth are easy to reach the 120 state of the least steps out,
Only for a time, any (M, N) (M2, N2), in accordance with the above obtained in S2=1) (M2, N2, face at least count
Final step is S1 + S2
CodePudding user response:
Correction: S2=(M2 , steps 1) leastCodePudding user response: