finish level3/the-grandest-staircase-of-them-all #2

Merged
seongbeom_park merged 2 commits from level3/the-grandest-staircase-of-them-all into main 2022-01-15 05:50:13 +00:00
Showing only changes of commit 52c22604f1 - Show all commits

View File

@ -0,0 +1,39 @@
import math
def solution(n):
memo = {}
return get_staircase_count(n, n-1, memo)
def get_staircase_count(blocks, cap, memo):
if blocks <= 0:
return 0
if cap <= 0:
return 0
if blocks == 1:
return 1
if cap >= blocks:
return 1 + get_staircase_count(blocks, blocks-1, memo)
if blocks not in memo:
memo[blocks] = {}
if cap in memo[blocks]:
return memo[blocks][cap]
count = 0
for height in range(1, cap+1):
count += get_staircase_count(blocks-height, height-1, memo)
memo[blocks][cap] = count
return count
tests = [
[1, 0],
[2, 0],
[3, 1],
[4, 1],
[5, 2],
[6, 3],
[200, 487067745]
]
for test in tests:
result = solution(test[0])
print(test[0], result == test[1], result, test[1])
print ""