如何使用深度优先搜索(DFS)了解河内塔问题? [英] How do I understand the Tower of Hanoi problem using Depth First Search (DFS)?

查看:97
本文介绍了如何使用深度优先搜索(DFS)了解河内塔问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想了解这个问题。



我有3个钉子和5个磁盘。我必须最终将最后一个磁盘送到目标挂钩。我可以移动磁盘但是较大的磁盘不能放在较小的磁盘上。



我一直在读'N-1'磁盘。这是指磁盘的数量,但程序如何知道哪个是最大的,哪个是最小的。我查了一些例子,没有明确地解决这个问题。 (至少我不认为他们这样做了)



此外,DFS是一个不知情的搜索,意味着必须根据每种可能的不同状态构建子节点移动。

我不确定这些状态是如何表示的。

还有什么东西将磁盘连接到它移动到的挂钉上。感觉就像我在代表代码下面遗漏了很多东西。

I am trying to understand the problem.

I have 3 pegs and 5 disks. I have to eventually get the last disk to the destination peg. I can move the disks but a larger disk cannot be on top of a smaller disk.

I keep reading 'N-1' disks. This refers to the number of disks but how does the program know which is the largest and which is the smallest. I've looked up examples and none explicitly addresses this. (at least i don't think they did)

Also DFS is an uninformed search meaning that child nodes have to be built from the different 'states' of each possible move.
I am not sure how these states are represented.
Also what connects the disk to the peg it was moved onto. It feels like I am missing a lot of things underneath the representing code.

推荐答案

请看我对这个问题的评论。很明显,应用任何算法所需的唯一状态是此刻每个挂钩上的磁盘数量。所以,这将是一个由3个整数组成的数组。我不明白这里有什么问题。这似乎太微不足道了。



-SA
Please see my comment to the problem. It's obvious that the only state needed to apply any algorithm is the number of disks on each peg at the moment. So, this would be an array of 3 integers. I don't understand what could be a problem here. It seems to be way too trivial.

—SA


这篇关于如何使用深度优先搜索(DFS)了解河内塔问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆