Formula for a dynamic programming problem about stairs

42 Views Asked by At

There is a known problem, so I quote it here

A child is running up a staircase with n steps and can hop either 1 step, 2 steps, or 3 steps at a time. How many possible ways the child can run up the stairs?

I have two questions here:

  1. How do I get an exact formula to calculate exact number for any i without writing a simulation?
  2. How can this formula be generalized for any k instead of just 3?

My math knowledge in dynamic programming is limiting me to "write a recursion, use memoization to cache results and see what simulation shows" but I'm not able to deduce a general formula to just put numbers and get out the result.