Fibonacci sequence solves the problem of the upper steps

Source: Internet
Author: User

The Fibonacci sequence (Fibonacci sequence), which was introduced by the mathematician Leonardo's Fibonacci (Leonardoda Fibonacci) as an example of rabbit reproduction, is also known as the "rabbit sequence", referring to a sequence of 0, 1, 1, 2, 3, 5, 8, 13, 21. 、...... In mathematics, the Fibonacci sequence is defined recursively as follows: F (0) =0,f (1) =1,f (n) =f (n-1) +f (n-2) (n≥2,n∈n*) in modern physics, quasi-crystalline structure, chemistry and other fields, the Fibonacci sequence has a direct application.

The characteristics of the series: the 1th item is 0, the 2nd item is the first 1, starting with the 3rd item, each item is equal to the sum of the first two items.

Title Description:

There is a staircase of a total of n-level, just at the beginning of you in the first level, if you can only step up one level or two, to embark on the nth level, how many methods?

Note: There are 0 ways to go from one level to the next.

function Taijie (n) {        var arr=[];        arr[0]=0;        arr[1]=0;        Arr[2]=1;        arr[3]=2;        for (Var i=4;i<=n;i++)        {            arr[i] =arr[i-1]+arr[i-2];        }        return arr[n];    }

  

Fibonacci sequence solves the problem of the upper 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.