import java.util.*; //动态规划 //设置dp【n】为到达n阶的跳法数,状态转移方程为dp【n】 = dp【n-1】 + dp【n-2】 //因为n- 2阶和n-1都可以一步跳到n public class Solution { public int jumpFloor (int number) { if (number ==1){ return 1; }else if (number == 2){ return 2; } int[] dp = new int[number + 1 ]; dp[0] = 0; dp[1] = 1; dp[2] = 2; for (int i = 3; i <= number ; i++) { dp[i] = dp[i-2] + dp[i-1]; } return dp[number]; } }