1.题目:
2.解析:
代码:
public int waysToStep(int n) {/**1.创建dp表2.初始化3.填表4.返回值*/int MOD = (int)1e9 + 7;//注意不能超出int范围,每做一次操作要取模//处理边界情况if(n == 1 || n == 2) return n;if(n == 3) return 4;//1.创建dp表int[] dp = new int[n+1];//0位置不算//2.初始化dp[1] = 1;dp[2] = 2;dp[3] = 4;//3.填表for(int i = 4; i <= n; i++)dp[i] = ((dp[i-1] + dp[i-2]) % MOD + dp[i-3]) % MOD;return dp[n];}