我需要在室内地图中创建一个具有所有连接(步骤,跳跃)的路径
比如AB, BC, BA, CB, ...
。假设我必须从A
转到I
算法怎么样?
附:我正在开发C#,但是任何伪代码或其他资源的链接都会受到赞赏。
答案 0 :(得分:1)
Use Breadth-First-Search (BFS) to construct a tree starting from A
.
When you reach the node I
, traverse the tree back up to the root (A
) by repeatedly going up the parent node i.e. I -> H -> G -> F -> C -> B -> A
.
As you do, you can retrieve the strings HI, GH, FG, CF, BC, AB
, which you can then list backwards for your final solution.