If the grid width is odd, then the number of inversions in a solvable situation is even.
If the grid width is even, and the blank is on an even row counting from the bottom (second-last, fourth-last etc), then the number of inversions in a solvable situation is odd.
If the grid width is even, and the blank is on an odd row counting from the bottom (last, third-last, fifth-last etc) then the number of inversions in a solvable situation is even.
That gives us this formula for determining solvability:
( (grid width odd)&&(#inversions even) ) || ( (grid width even)&&((blank on odd row from bottom)==(#inversions even)) )Solvability of the Tiles Gamewww.cs.bham.ac.uk
希望对于你有帮助。