robbery_optim.py 502 B

123456789101112131415161718192021222324
  1. '''
  2. @author: olivier.massot, 2019
  3. '''
  4. import sys
  5. # houses = [int(input()) for _ in range(int(input()))]
  6. houses = [1, 15, 10, 13, 16]
  7. print(houses, file=sys.stderr)
  8. to_rob = []
  9. def max_independent_weight(weights):
  10. def with_and_without(i):
  11. if i < 0 or i >= len(weights):
  12. return 0, 0
  13. right = with_and_without(i + 1)
  14. return weights[i] + right[1], max(right)
  15. return max(with_and_without(0))
  16. print(max_independent_weight(houses))