Created
August 13, 2012 13:15
-
-
Save wyukawa/3340614 to your computer and use it in GitHub Desktop.
部分和問題
This file contains hidden or 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 dfs(i, sum, a, k): | |
| if i == len(a): | |
| return sum == k | |
| if dfs(i+1, sum, a, k): | |
| return True | |
| if dfs(i+1, sum+a[i], a, k): | |
| return True | |
| return False | |
| def solve(a, k): | |
| if dfs(0, 0, a, k): | |
| print "Yes" | |
| else: | |
| print "No" | |
| solve([1, 2, 4, 7], 13) | |
| solve([1, 2, 4, 7], 15) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment