The main effect of the topic
As pictured above, this is a dancing machine, with the initial state of two feet in 0, the state as (0, 0), and then the dance opportunity to give you a series of dance directions, such as 2,3,4,2,3 ...
Each time you have to choose one foot to move to the grid corresponding to the digital direction.
For example, from the initial state (0,0), to move to 1, you can select the left or right foot to move up, the corresponding state is (1, 0), (0,1)
There is a limit, in addition to the initial state can be (0, 0), after the two feet can not be in a grid at the same time!
Move the foot to expend the physical strength, moves from 0 to other each is consumes 2, from 1,2,3,4, if is moves to the adjacent lattice, for instance 1->2, 1->4, 3->2, 4->3, consumes the physical strength 3
If it is moving to the opposite of the lattice, such as 1->3, 2->4, energy consumption 4.
If a certain step, stop not moving, energy consumption 1
To give a bunch of directions, ask how much physical energy can be used to complete these movements?
Ideas
F (i, j, K), representing the minimum physical strength of the step I, the state of (J,K)
So it's not difficult to launch the transfer equation:
Assuming that the current dance step is in S, then all states that conform to this stage are:
F (I, 0..4, s), F (I, S, 0...4)
Then the minimum physical charge for the next step can be rolled out according to the state above.
Let's say the next dance step is next.
So
If f (I, J, s), (0<=j<=4) state up to
You can launch the next state
F (I+1, j, s) = f (i, j, K) + 1; Stop at the current do not move
F (i+1, next, s) = min{F (i, J, s) + consume (j, Next)}
F (I+1, j, next) = min{F (i, J, s) + consume (s, next)}
Similarly, if f (I, S, j), (0<=j<=4) state can be up to
You can also launch the next state:
F (I+1, S, j) = f (i, j, K) + 1; Stop, stay where you are.
F (I+1, Next, j) = min{F (i, S, j) + consume (s, next)}
F (i+1, S, next) = min{F (i, S, j) + consume (j, Next)}