nestedApply :: (Applicative f, Applicative g) => g (f (a -> b)) -> f a -> g (f b)
Run Code Online (Sandbox Code Playgroud)
正如类型所示,如何将其(a->b)应用于a上下文中f?
感谢帮助。
我正在研究一个关于单词阶梯的问题,带有一些额外的约束(给出了单词列表,并且阶梯仅由这些单词构建,而不是整个英语)。\n除了传统的Word Ladder问题:
\n\n\n\n
\n- 最小化单词阶梯的字母距离。
\n
例如,“aab”和“aaa”的距离为 1,因为“b”是字母表中的第二个字母,而“a”是第一个字母。“bbb”和“bwb”的距离为 21,因为“b”是字母表中的第二个字母,而“w”是第二十三个字母。
\n\n\n\n
\n- 我们需要在梯子中使用一组特定单词中的一个,例如“绕行”。
\n
这意味着,给定原始单词的单词列表 (>= 1),这些单词中至少有一个必须出现在单词梯中。
\n该问题有一个复杂度约束,即 O(Elog(W) + Wlog(W))),其中
\n\n\nE是仅相差一个字母的单词对的数量
\nW是单词总数
\n
请注意,这种复杂性不涉及任何与“绕行”字的大小相关的术语。
\n# One example is (we denote the word as indices in the list):\nwords = [\xe2\x80\x99aaa\xe2\x80\x99,\xe2\x80\x99bbb\xe2\x80\x99,\xe2\x80\x99bab\xe2\x80\x99,\xe2\x80\x99aaf\xe2\x80\x99,\xe2\x80\x99aaz\xe2\x80\x99,\xe2\x80\x99baz\xe2\x80\x99,\xe2\x80\x99caa\xe2\x80\x99,\xe2\x80\x99cac\xe2\x80\x99,\xe2\x80\x99dac\xe2\x80\x99,\xe2\x80\x99dad\xe2\x80\x99,\xe2\x80\x99ead\xe2\x80\x99,\xe2\x80\x99eae\xe2\x80\x99,\xe2\x80\x99bae\xe2\x80\x99,\xe2\x80\x99abf\xe2\x80\x99,\xe2\x80\x99bbf\xe2\x80\x99]\nstart word = 0 # ("aaa")\nend word = 1 # ("bbb")\ndetour = [12] # ("bae")\n# The result path is: [0, 6, 7, 8, 9, 10, 11, …Run Code Online (Sandbox Code Playgroud)