Created
June 8, 2013 08:01
-
-
Save st0le/5734468 to your computer and use it in GitHub Desktop.
Longest Increasing Sequence DFS
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
def longest_increasing_subsequence_dfs(lst): | |
lis_seq = [] | |
sz = len(lst) | |
def lis(index,seq): | |
if len(seq) + (sz - index) < len(lis_seq): return #prune the rest. | |
for i in xrange(index,sz): | |
if seq[-1] < lst[i]: | |
seq.append(lst[i]) | |
lis(i+1,seq) | |
seq.pop() | |
else: | |
if len(seq) > len(lis_seq): | |
l = lis_seq | |
l[:] = seq | |
for i in xrange(sz): | |
lis(i + 1,[lst[i]]) | |
return lis_seq |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment