Abnormal jumping steps
- Time limit: 1 seconds space limit: 32768K
The topic describes a frog can jump up to 1 steps at a time, can also jump on the 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. Analysis Tomorrow is a Fibonacci sequence, and we step-by-step out of its general formula. Set the number of steps to N, the total hop method is jumps n  JUMPS1 16 now guess its formula is Fbon ICC (N) = 2 * FBONICC (n-1) List 4 of all jumps 5 of all jump method 1111 1111 (1) 2 11 2 11 (1) 1 2 1 1 2 1 (1) 1 1 2 1 1 2 (1) 2 2&NB Sp 2 2 (1) 1 3 1 3 (1) 3 1 3 1 (1) 4 4 (1) 111 (+) 2 1 (+) 1 2 (+) 1 1 (2 + 1) 2 (2+1) 1 (3+1) 3 (+) (4+1) so should be able to see the law this time! i.e. FBONICC (n) = 2 * FBONICC (n-1) c++ code implements recursive implementation
Class Solution {public: int jumpfloorii (int number) { if (number = = 1) return 1; else return 2 * jumpfloorii (NUMBER-1); }};
Non-recursive implementation
class Solution {public: int jumpfloorii (int number ) { Longlong1; for (int2; I <= number;i++) 2 ; return FIBONICC; }};
(original) sword refers to the abnormal jumping steps