DP 的递推关系?
假设您有一本包含有效单词的字典。
给定一个删除了所有空格的输入字符串,确定该字符串是否由有效单词组成。
您可以假设字典是一个提供 O(1) 查找的哈希表。
请给出一个递推关系。我在书上找到了这个问题,但是书上没有给出答案?
Suppose you have a dictionary that contains valid words.
Given an input string with all spaces removed, determine whether the string is composed of valid words or not.
You can assume the dictionary is a hashtable that provides O(1) lookup.
Please give a recurrence relation for this. I found this question in a book , but the book gives no answer?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是我在 Mathematica 中为最近的代码高尔夫开发的代码。
它是一种最小匹配、非贪婪、递归算法。这意味着句子“the pen is mighter than the Sword”(不带空格)返回 {“the pen is might er than the Sword} :)
示例输入
输出
HTH
Here is a code in Mathematica I started to develop for a recent code golf.
It is a minimal matching, non greedy, recursive algorithm. That means that the sentence "the pen is mighter than the sword" (without spaces) returns {"the pen is might er than the sword} :)
Sample Input
Output
HTH