(formerly) The sword refers to the abnormal jumping steps

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.