Title: A frog can jump on a Class 1 level, you can also hop on level 2 ...... n It can also jump on stage. The frog jumped seeking a total of n grade level how many jumps.
About this problem, provided that jumps n th there will be a level of order n. analyse as below:
f(1) = 1
f (2) = f (2-1) + f (2-2) // f (2-2) represents a second-order frequency hop 2 order.
f(3) = f(3-1) + f(3-2) + f(3-3)
...
f(n) = f(n-1) + f(n-2) + f(n-3) + ... + f(n-(n-1)) + f(n-n)
Description:
1) where f (n) represents n-th time step has 1,2, ... n-th order of hop count method.
2) n = 1, only one kind of jumps, f (1) = 1
3) n = 2, there will be two jump mode, a first-order or second-order, which return to the problem (1), f (2) = f (2-1) + f (2-2)
4) n = 3, there will be three kinds of jump mode, the first-order, second order, third order,
Then that the first stage out of the back rest 1: f (3-1); 2 out of the first order, the remaining f (3-2); 3 first order, the remaining f (3-3)
It was concluded that f (3) = f (3-1) + f (3-2) + f (3-3)
5) When n = n, there are n hops manner, the first-order, second order ... n order, concluded:
f(n) = f(n-1)+f(n-2)+...+f(n-(n-1)) + f(n-n) => f(0) + f(1) + f(2) + f(3) + ... + f(n-1)
6) From the above it is already a conclusion, but for simplicity, we can continue to simplify:
f(n-1) = f(0) + f(1)+f(2)+f(3) + ... + f((n-1)-1) = f(0) + f(1) + f(2) + f(3) + ... + f(n-2)
f(n) = f(0) + f(1) + f(2) + f(3) + ... + f(n-2) + f(n-1) = f(n-1) + f(n-1)
It can be drawn:
f(n) = 2*f(n-1)
7) definitive conclusions, in step n-th order, a 1, 2, ... n-th order mode when the jump, jump method is somehow:
| 1 ,(n=0 )
f(n) = | 1 ,(n=1 )
1 public class Solution { 2 public int JumpFloorII(int target) { 3 if(target <= 2){ 4 return target; 5 } 6 return 2*JumpFloorII(target-1); 7 } 8 }