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

前端 未结 13 833
时光说笑
时光说笑 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:53

    Below is the several ways to use 1 , 2 and 3 steps

    1: 1
    2: 11   2
    3: 111 12 21 3
    4: 1111 121 211 112 22 13 31
    5: 11111 1112 1121 1211 2111 122 212 221 113 131 311 23 32
    6: 111111 11112 11121 11211 12111 21111 1113 1131 1311 3111 123 132 312 321 213 231 33 222 1122 1221 2211 1212 2121 2112
    

    So according to above combination the soln should be:

    K(n) = K(n-3) + K(n-2) + K(n - 1)
    k(6) = 24 which is k(5)+k(4)+k(3) = 13+7+4
    

提交回复
热议问题