n steps with 1, 2 or 3 steps taken. How many ways to get to the top?

前端 未结 13 847
时光说笑
时光说笑 2020-12-08 08:12

If we have n steps and we can go up 1 or 2 steps at a time, there is a Fibonacci relation between the number of steps and the ways to climb them. IF and ONLY if we do not co

13条回答
  •  隐瞒了意图╮
    2020-12-08 08:51

    I would say that the formula will look in the following way:

    K(1) = 1
    K(2) = 2
    k(3) = 4
    K(n) = K(n-3) + K(n-2) + K(n - 1)
    

    The formula says that in order to reach the n'th step we have to firstly reach:

    • n-3'th step and then take 3 steps at once i.e. K(n-3)
    • or n-2'th step and then take 2 steps at once i.e. K(n-2)
    • or n-1'th step and then take 1 steps at once i.e. K(n-1)

    K(4) = 7, K(5) = 13 etc.

    You can either utilize the recursive formula or use dynamic programming.

提交回复
热议问题