Skip to content

Instantly share code, notes, and snippets.

@qiuyujx
Created November 8, 2020 12:37
Show Gist options
  • Save qiuyujx/ca3e4ca495522cc2d0a2c3a3f9033d42 to your computer and use it in GitHub Desktop.
Save qiuyujx/ca3e4ca495522cc2d0a2c3a3f9033d42 to your computer and use it in GitHub Desktop.
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