|
| 1 | +3154\. Find Number of Ways to Reach the K-th Stair |
| 2 | + |
| 3 | +Hard |
| 4 | + |
| 5 | +You are given a **non-negative** integer `k`. There exists a staircase with an infinite number of stairs, with the **lowest** stair numbered 0. |
| 6 | + |
| 7 | +Alice has an integer `jump`, with an initial value of 0. She starts on stair 1 and wants to reach stair `k` using **any** number of **operations**. If she is on stair `i`, in one **operation** she can: |
| 8 | + |
| 9 | +* Go down to stair `i - 1`. This operation **cannot** be used consecutively or on stair 0. |
| 10 | +* Go up to stair <code>i + 2<sup>jump</sup></code>. And then, `jump` becomes `jump + 1`. |
| 11 | + |
| 12 | +Return the _total_ number of ways Alice can reach stair `k`. |
| 13 | + |
| 14 | +**Note** that it is possible that Alice reaches the stair `k`, and performs some operations to reach the stair `k` again. |
| 15 | + |
| 16 | +**Example 1:** |
| 17 | + |
| 18 | +**Input:** k = 0 |
| 19 | + |
| 20 | +**Output:** 2 |
| 21 | + |
| 22 | +**Explanation:** |
| 23 | + |
| 24 | +The 2 possible ways of reaching stair 0 are: |
| 25 | + |
| 26 | +* Alice starts at stair 1. |
| 27 | + * Using an operation of the first type, she goes down 1 stair to reach stair 0. |
| 28 | +* Alice starts at stair 1. |
| 29 | + * Using an operation of the first type, she goes down 1 stair to reach stair 0. |
| 30 | + * Using an operation of the second type, she goes up 2<sup>0</sup> stairs to reach stair 1. |
| 31 | + * Using an operation of the first type, she goes down 1 stair to reach stair 0. |
| 32 | + |
| 33 | +**Example 2:** |
| 34 | + |
| 35 | +**Input:** k = 1 |
| 36 | + |
| 37 | +**Output:** 4 |
| 38 | + |
| 39 | +**Explanation:** |
| 40 | + |
| 41 | +The 4 possible ways of reaching stair 1 are: |
| 42 | + |
| 43 | +* Alice starts at stair 1. Alice is at stair 1. |
| 44 | +* Alice starts at stair 1. |
| 45 | + * Using an operation of the first type, she goes down 1 stair to reach stair 0. |
| 46 | + * Using an operation of the second type, she goes up 2<sup>0</sup> stairs to reach stair 1. |
| 47 | +* Alice starts at stair 1. |
| 48 | + * Using an operation of the second type, she goes up 2<sup>0</sup> stairs to reach stair 2. |
| 49 | + * Using an operation of the first type, she goes down 1 stair to reach stair 1. |
| 50 | +* Alice starts at stair 1. |
| 51 | + * Using an operation of the first type, she goes down 1 stair to reach stair 0. |
| 52 | + * Using an operation of the second type, she goes up 2<sup>0</sup> stairs to reach stair 1. |
| 53 | + * Using an operation of the first type, she goes down 1 stair to reach stair 0. |
| 54 | + * Using an operation of the second type, she goes up 2<sup>1</sup> stairs to reach stair 2. |
| 55 | + * Using an operation of the first type, she goes down 1 stair to reach stair 1. |
| 56 | + |
| 57 | +**Constraints:** |
| 58 | + |
| 59 | +* <code>0 <= k <= 10<sup>9</sup></code> |
0 commit comments