Advertisement
Cloude

PE2b

Feb 21st, 2020
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. def maximum_cost(shop, total):
  2. final = [-1]
  3.  
  4. def works(shopa, totala):
  5. if totala < 0:
  6. return False
  7. elif totala == 0:
  8. return True
  9. else:
  10. ans = False
  11. for bundleb in shopa:
  12. if works(shopa, totala - get_size(bundleb)):
  13. ans = True
  14. break
  15. return ans
  16.  
  17. def recur(shopb, totalb):
  18. possible = []
  19. if totalb <= 0:
  20. return [0]
  21. else:
  22.  
  23. for bundle in shopb:
  24. if works(shopb, totalb - get_size(bundle)) or totalb == 0:
  25. for i in recur(shopb, totalb - get_size(bundle)):
  26. possible.append(get_cost(bundle) + i)
  27. return possible
  28.  
  29. for bundlea in shop:
  30. if is_pink_rose(bundlea):
  31. final.append(get_cost(bundlea) + max(recur(shop, total - get_size(bundlea))))
  32.  
  33. return max(final)
  34.  
  35.  
  36.  
  37. for bundlea in shop:
  38. if is_pink_rose(bundlea):
  39. final.append(get_cost(bundlea) + max(recurhelper(shop, total - get_size(bundlea))))
  40.  
  41. return max(final)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement