Created
December 5, 2015 09:15
-
-
Save mcpower/0f678d5b278b1fa8d229 to your computer and use it in GitHub Desktop.
This file contains 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
L = [int(x) for x in "1307 2716 3449 2758 4597 5191 1465 2259 2829 3004".split()] | |
N = 20000 | |
array = [[]] + [None for i in range(N-1)] | |
minimum, route = float("inf"), None | |
for num in L: | |
todo = [] | |
for index in range(N): | |
if array[index] is not None: | |
if index + num >= N: | |
if index + num < minimum: | |
minimum, route = index + num, array[index] + [num] | |
break | |
if array[index+num] is None: | |
todo.append(index) | |
for index in todo: | |
array[index+num] = array[index] + [num] | |
print(minimum, route) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment