Created
May 4, 2018 01:18
-
-
Save jesuyedavid/ec65ee97903e55ed09e2dffdb6fa1fb5 to your computer and use it in GitHub Desktop.
Davis has s staircases in his house and he likes to climb each staircase 1,2, or 3 steps at a time. Being a very precocious child, he wonders how many ways there are to reach the top of the staircase. Given the respective heights for each of the s staircases in his house, find and print the number of ways he can climb each staircase on a new lin…
This file contains hidden or 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
countStaircase={} | |
def countSteps(n): | |
if n in countStaircase: | |
return countStaircase[n] | |
elif n==0: | |
return 1 | |
elif n<0: | |
return 0 | |
else: | |
curCount=0 | |
curCount+=countSteps(n-3) | |
curCount+=countSteps(n-2) | |
curCount+=countSteps(n-1) | |
countStaircase[n]=curCount | |
return curCount | |
s = int(raw_input().strip()) | |
for a0 in xrange(s): | |
n = int(raw_input().strip()) | |
print(countSteps(n)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Davis has s staircases in his house and he likes to climb each staircase 1,2, or 3 steps at a time.
Being a very precocious child, he wonders how many ways there are to reach the top of the staircase.
Given the respective heights for each of the s staircases in his house, find and print the number of ways he can
climb each staircase on a new line.
Input Format
The first line contains a single integer,s, denoting the number of staircases in his house.
Each line i of the s subsequent lines contains a single integer,n, denoting the height of staircase i.
Constraints
Subtasks
Output Format
For each staircase, print the number of ways Davis can climb it in a new line.
Sample Input
3
1
3
7
Sample Output
1
4
44
*/