hi i need help with this problem ( it is a java coding problem)
please give me the answer and the code to this problem

Alex runs up a staircase with n steps, and can hop either 1, 2, or 3 steps at a time. Count how many possible ways the child can run up the stairs.

Respuesta :

Say child has to take n steps.

At every step the child has 3 options, to take 1 step, 2 step or 3 steps.

So if child take 1 step then find the number of ways to complete n-1 steps +1.

Similarly if child take 2 steps then find the number of ways to complete n-2 steps +1.

If child take 3 step then find the number of ways to complete n-3 steps +1.

So total number of ways to complete n steps = No of ways to complete (n-1)steps + No of ways to complete (n-2)steps + No of ways to complete (n-3)steps +1.

Answer:

4

Explanation:

If we consider a typical staircase with standard design, there is the possibility to move up the staircase by taking a single step at a time. In addition, it is also possible to take two steps followed by one step. It is also possible to take one step first followed by two steps. Lastly, it is also possible to take three steps. Therefore, the possible ways (N) will be:

N = S(1,1,1) + S(2,1) + S(1,2) + S(3) = 4