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