Abnormal jumping steps

Source: Internet
Author: User

A frog can jump up to 1 steps at a time, or jump up to 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.

Because n steps, the first step has n kinds of jumping method: Jump 1 level, jump 2 level, to jump N level
Jump 1 levels, leaving the n-1 level, then the jumping method is F (n-1)
Jump 2 levels, leaving the n-2 level, then the jumping method is F (n-2)
So f (n) =f (n-1) +f (n-2) +...+f (1)
Because F (n-1) =f (n-2) +f (n-3) +...+f (1)
So f (n) =2*f (n-1)

 

If target = 0, the description is skipped directly, otherwise 1 is returned; otherwise, there is always a selection in target, the steps that each selection contains are all done, recursion to the 0 end loop, and the result is merged.

 
 Public int Jumpfloorii (int  target) {        if (target = = 0) {
return 1;
}
int count = 0
for (int i = 1; i<target;i++) {
Count + = Jumpfloorii (target-i);
}
return count;
}
}

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.