Algorithm 13: Step jumping

Source: Internet
Author: User

ASIDE: today, I am so tired, but I decided to write one to stick to it. However, the question is so watery that you can entertain yourself!

[Topic] A step has a total of N levels. A jump can take the first or second order. This section describes the total number of medium hops and analyzes the time complexity.

[Thinking path] from special to general ideas. If there is only one level, there is only one method of jumping. If there is one level 2, so there is a 2 middle hop method (skip level 1 and then skip level 1, and then skip level 2 at a time). What if there is level n? Suppose we have the Skip method in F (n) for the Level n step. In Order N, we consider that if the first hop has two options: the first hop has the Level 1, the rest of the n-1 order has F (n-1) Jump method; the first jump level 2, The Rest Of The N-2 order F (n-2) Jump method, then the total number of hops is F (n-1) + f (n-2 ). Here we can see that this is the recursive formula of the Fibonacci series, but the first two items are slightly different. The written mathematical expressions are as follows:

For the specific Fibonacci sequenceCodeAndAlgorithmIn [algorithm 02], we have discussed the time complexity analysis in great detail and will not go into details. If you are interested, you can go back and take a look.

 

Note:

1) Compile all the code environments in this blogWin7 + vc6. All code has been debugged by the blogger.

2) BloggerPython27This blogArticleCopyright. For Network reprinting, please indicate the sourceHttp://www.cnblogs.com/python27/. You have any suggestions for solving the problem. Please feel free to comment on them.

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.