Embercode
✕
Dynamic ProgrammingCoding problems

Dynamic Programming: coding problems

Write a program that reads the input and prints the answer. Run checks it against every test, including hidden ones.

0 of 7 solved

  • A tower has n steps. You start on the ground, which counts as step 0. Each move climbs 1 step or 2 steps. Count the different ways to reach the top, step n. Two ways are different when the sequence of moves is different.

    Ground rule: when n is 0 you are already at the top, so there is 1 way (do nothing).

    Constraints: 0 <= n <= 45. The answer fits in a long long.

    Input. One integer n.

    Output. One integer: the number of ways to reach step n.

    Example 1 input

    5
    

    Output

    8
    

    Example 2 input

    10
    

    Output

    89