daily pastebin goal
52%
SHARE
TWEET

Untitled

a guest Oct 21st, 2018 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python
  2.  
  3. ## YES
  4. # n = 4
  5. # a = [1, 2, 4, 7]
  6. # k = 13
  7.  
  8. ## NO
  9. n = 4
  10. a = [1, 2, 4, 7]
  11. k = 15
  12.  
  13. def dfs(i, sum):
  14.     if i == len(a):
  15.         return sum == k
  16.  
  17.     if dfs(i + 1, sum):
  18.         return True
  19.  
  20.     if dfs(i + 1, sum + a[i]):
  21.         return True
  22.  
  23.     return False
  24.  
  25. def main():
  26.     if dfs(0, 0):
  27.         print "Yes"
  28.     else:
  29.         print "No"
  30.  
  31. main()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top