Guest User

eHázi q/26594 v2

a guest
Nov 1st, 2019
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.68 KB | None | 0 0
  1. stairs = (20, 30, 50, 30)
  2. max_step = 100
  3.  
  4. def main(stairs, max_step):
  5.     known = dict()
  6.     p = possibilities(stairs, max_step, known)
  7.     print(p)
  8.  
  9. def possibilities(stairs, max_step, known):
  10.     ind = 4- len(stairs)
  11.     if (len(stairs) == 1 and stairs[0] <= max_step) or len(stairs)==0:
  12.         return 1
  13.    
  14.     p = 0
  15.     for i in range(1,len(stairs)+1):
  16.         down = stairs[:i]
  17.         up= stairs[i:]
  18.  
  19.         if sum(down) > max_step:
  20.             break
  21.         elif up in known:
  22.             p += known[up]
  23.         else:
  24.             p_up = possibilities(up, max_step, known)
  25.             known[up] = p_up
  26.             p += p_up
  27.     return p
  28.  
  29. main(stairs, max_step)
Advertisement
Add Comment
Please, Sign In to add comment