100 question _ 23 jump steps

Source: Internet
Author: User

A step has a total of N levels. If you can skip 1 level at a time, you can also skip 2 levels. Calculate and analyze the total number of hops in totalAlgorithmTime complexity.

 

First, consider the simplest situation. If there is only one level, there is obviously only one method to skip. If there are two steps, there are two ways to skip: one is to skip level 1 each time, and the other is to skip level 2 at a time. Now let's discuss the general situation. We regard the jump Method for n-level steps as a function of N and record it as F (n ). When N> 2, there are two different options for the first hop: one is the first hop with only one level. At this time, the number of hops equals to the number of hops for the next n-1 level step, that is F (n-1); another option is the first jump level 2, at this time the number of Jump method is equal to the number of the next step of the N-2 level, that is, F (n-2 ). Therefore, F (n) = f (n-1) + (F-2) of different hops at N-level steps ).

To sum up, get the recursive formula:

From this perspective, we can see that this is actually the Fibonacci series. We have discussed it before. Please click here to view details.

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.