Created
May 21, 2017 17:05
-
-
Save sat0b/5703409beb99f6b7f63661a61f5c4520 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
| # 部分和問題 蟻本 p.34 | |
| # aからいくつか選び合計がkとなるかを判定 | |
| n = 4 | |
| a = [1, 2, 4, 7] | |
| k = 13 | |
| def dfs(i, sum): | |
| if i == n: | |
| return sum == k | |
| if dfs(i + 1, sum): | |
| return True | |
| if dfs(i + 1, sum + a[i]): | |
| return True | |
| return False | |
| if dfs(0, 0): | |
| print("Yes") | |
| else: | |
| print("No") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment