Created
June 4, 2013 21:43
-
-
Save st0le/5709872 to your computer and use it in GitHub Desktop.
Subset Sum 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 subset_sum(lst,K): | |
lst.sort() | |
sz = len(lst) | |
def subset_sum_helper(index,s): | |
if index == sz or s >= K : return s == K | |
return subset_sum_helper(index + 1, s) or subset_sum_helper(index + 1, s + lst[index]) | |
return subset_sum_helper(0 , 0 ) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment