Created
April 6, 2021 17:58
-
-
Save p10rahulm/7a88d03dfac8bb19373b664a6ecd2825 to your computer and use it in GitHub Desktop.
Dynamic Programming Stuff
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
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