Created
November 8, 2020 12:37
-
-
Save qiuyujx/ca3e4ca495522cc2d0a2c3a3f9033d42 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
def max_vote_recursive(states, days_left, index): | |
# Terminating conditions | |
if len(states) == 0 or index >= len(states) or days_left <= 0: | |
return 0 | |
# If we have enough days, go to this state | |
votes_if_go = 0 | |
if states[index]['days'] <= days_left: | |
votes_if_go = states[index]['votes'] + max_vote_recursive(states, days_left - states[index]['days'], index + 1) | |
# If we don't go to this state | |
votes_if_not_go = max_vote_recursive(states, days_left, index + 1) | |
return max(votes_if_go, votes_if_not_go) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment