但是,改变一下策略,搜索到了更少步数的路径。
在2#的第1步到达第2图之后,保持{1,7,8}不动,将{2,3,4,5,6,0}调序为{0,6,5,4,3,2},搜索到最短路径为15步:
{{2, 3, 4, 5, 6, 0},
{2, 3, 4, 5, 0, 6},
{2, 3, 0, 5, 4, 6},
{0, 3, 2, 5, 4, 6},
{3, 0, 2, 5, 4, 6},
{3, 5, 2, 0, 4, 6},
{3, 5, 2, 6, 4, 0},
{3, 5, 2, 6, 0, 4},
{3, 5, 0, 6, 2, 4},
{0, 5, 3, 6, 2, 4},
{5, 0, 3, 6, 2, 4},
{5, 6, 3, 0, 2, 4},
{5, 6, 3, 4, 2, 0},
{5, 6, 3, 4, 0, 2},
{5, 6, 0, 4, 3, 2},
{0, 6, 5, 4, 3, 2}}
剩下部分,保持{2,3,4,5,6}不动,将{0,1,7,8}调序为{7,8,0,1},搜索最短路径为4步:
{{0, 1, 7, 8},
{7, 1, 0, 8},
{7, 0, 1, 8},
{7, 8, 1, 0},
{7, 8, 0, 1}}
最后,合起来为1+15+4=20步。 |