Created
May 10, 2020 12:45
-
-
Save ariG23498/9e8d6ea6f7e06e3661344773f2770f41 to your computer and use it in GitHub Desktop.
Foobar problem on staircase
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
def print_util(mat): | |
for i in mat: | |
for j in i: | |
print(j, end=" ") | |
print() | |
def solution(number): | |
mat = [[0 for i in range(number+1)] for i in range(number+1)] | |
mat[0][0] = 1 | |
# The first row is skipped | |
for summands in range(1,number+1): | |
for sums in range(number+1): | |
mat[summands][sums] = mat[summands-1][sums] | |
if sums >= summands: | |
mat[summands][sums] += mat[summands-1][sums - summands] | |
return mat[-1][-1] -1 | |
print_util(mat) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment