求解法!
Given 2x4 matrix it contains numbers in the range 1-8.
For eg :
[4,2,6,5
1,8,7,3]
You have 3 operations:
-
Rotate : Middle 4 numbers rotate in clockwise manner.
[4,2,6,5
1,8,7,3]
becomes
[4, 8,2 ,5
1, 7,6 ,3] -
Swap : swaps the two arrays
[4,2,6,5
1,8,7,3]
becomes
[1,8,7,3
4,2,6,5] -
Shift (right) :
[4,2,6,5
1,8,7,3]
becomes
[ 5 ,4,2,6,
3 ,1,8,7]
Your goal is to reach following state and return how many minimum operations would it take to reach that state.
[1,2,3,4
5,6,7,8]
感觉很像 https://leetcode.com/problems/sliding-puzzle/description/