Created
November 28, 2013 04:59
-
-
Save shurane/7687422 to your computer and use it in GitHub Desktop.
dynamic programming for great win. Problem: putting spaces back into a string of words.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
obamasaysheplanstovetothebillinmanhattan | |
router | |
doesnt | |
suck | |
haha | |
this | |
is | |
more | |
words | |
obama | |
n = length of string | |
m = number of words in dictionary | |
l = average length of word | |
m^(n/l) | |
m*n*n^2*(n/l) | |
(n) + (n - 1) + (n - 2) + ... + (0) | |
# n^2 (startindex,endindex) pairs, memoize all n^2 lookups. | |
F("") = TRUE | |
F(string) = any([ string.substring(0,i).isInDictionary() and F(string.substring(i,len(string))) | |
for i in range len(string)]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment