Last active
March 22, 2024 17:14
-
-
Save rongpenl/33d69b28c79aaf39b222a718d6fa5eff to your computer and use it in GitHub Desktop.
Answer for the mail delivery problem using dynamic programming
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
# ron and math community post: https://www.youtube.com/post/Ugkx321bNyuBEYuPthOIEKpbaqz04Ujat1f_ | |
def a(n): | |
if n < 3: | |
return 1 | |
if n not in memo_a: | |
memo_a[n] = a(n - 2) + a(n - 3) | |
return memo_a[n] | |
def b(n): | |
if n not in memo_b: | |
memo_b[n] = a(n - 1) + a(n - 2) | |
return memo_b[n] | |
memo_a = {} | |
memo_b = {} | |
print(a(19) + b(19)) # 351 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment