字符串转换字符串

2023-09-11 04:25:56 作者:我才不会哭睫毛膏太贵了

我碰到下面的文章,这让我感兴趣,这方面的问题。

I came across the following article which got me interested in this particular problem.

由于两个词CAT,远确定是否可以从第一个获得   通过单一的变换有效的话....例如第二1   改造可以让你从猫CAR改变T可R,然后又   让你的车到FAR改变C至F ......都是有效的英语   话。

Given two words "CAT", "FAR" determine if you can get from the first to the second via single transformations of valid words....e.g. 1 transformation gets you from CAT to CAR changing T to R, then another gets you from CAR to FAR changing the C to F...all are valid english words.

任何想法?真的不知道如何开始是诚实的。如果你在正确的方向指向我,那就够了。谢谢!

Any ideas? Not really sure how to begin to be honest. If you point me in the right direction, then that will be enough. Thanks!

推荐答案

作为this回答(感谢,AIX),这是一个最短路径问题,可以有效地解决与的 A *算法使用汉明距离(即通过信件数量这两个词的不同)作为一种启发式的。

As noted in this answer (thanks, aix), this is a shortest-path problem, and can be efficiently solved with the A* algorithm using the Hamming distance (i.e. the number of letters by which two words differ) as a heuristic.