Jumping Step Title Description
A frog can jump up to 1 steps at a time, or jump up to level 2. Ask the frog to jump on an n-level step with a total number of hops.
Thinking of solving problems
When N=1, the number of times f (n) = 1.
When n=2, the number of times f (n) = 2. (11 or 2)
When n>2, the current step can jump one level, you can also jump two levels, the number of f (n) =f (n-1) +f (n-2).
Implementation code
class Solution {public: number) { if (number2) returnnumber; else return jumpFloor(number1) + jumpFloor(number2); }};
Abnormal jumping steps
A frog can jump up to 1 steps at a time, or jump up to level 2. Ask the frog to jump on an n-level step with a total number of hops.
Title Description
A frog can jump up to 1 steps at a time, or jump up to level 2 ... It can also jump on n levels. Ask the frog to jump on an n-level step with a total number of hops.
Thinking of solving problems
When the number of steps is n, it can be divided into the following steps to complete:
The number of steps for the first hop is S, and the number of steps to skip is T, then:
(1) S=1, t (n) = t (n-1)
(2) s=2, t (n) = t (n-2)
.
.
.
(n) s=n, t (n) = t (0) = 1
So the total number of steps to skip can be expressed as:
T (n) = t (0) + t (1) + t (2) + ... + t (n-1)
Because T (0) = t (1) = 1, so t (n) = 2^ (n-1)
Implementation code
class Solution {public: intjumpFloorII(int number) { return pow(21); }};
The step problem of recursion