Skip to content

Instantly share code, notes, and snippets.

@p10rahulm
Created April 6, 2021 17:58
Show Gist options
  • Save p10rahulm/7a88d03dfac8bb19373b664a6ecd2825 to your computer and use it in GitHub Desktop.
Save p10rahulm/7a88d03dfac8bb19373b664a6ecd2825 to your computer and use it in GitHub Desktop.
Dynamic Programming Stuff
import numpy as np
def maxPayout(payouts, cooldown):
n = len(payouts)
payouts = payouts
cooldown = cooldown
opt = np.zeros([n, n])
print(opt)
for t in range(n):
for j in range(n):
if j == n - 1 - t:
opt[j][t] = payouts[n - 1 - j]
elif j > n - 1 - t:
opt[j][t] = max(opt[j - 1][t], payouts[n - 1 - j] + opt[j -1- cooldown[n - 1 - j]][t])
print(opt)
payouts = [2, 1, 4, 9, 6]
cooldown = [1, 0, 1, 2, 3]
maxPayout(payouts, cooldown)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment