贴一下第一题的代码,力扣【爬楼梯】变种,一次可以取1、2、3、4个,动态规划,递推到n为止。 有同学能分享下第二题的题目和解法吗?没仔细看第二题跳过了,现在复盘想不起来了... public static void main(String[] args) { Scanner in = new Scanner(System.in); while (in.hasNext()) { int n = in.nextInt(); int[] dp = new int[20000]; dp[0] = 1; dp[1] = 1; dp[2] = 2; dp[3] = 4; dp[4] = 8; if (n < 5) { System.out.println(dp[n]); } else { for (int i = 5; i <= n; i++) { dp[i] = dp[i - 1] + dp[i - 2] + dp[i - 3] + dp[i - 4]; } System.out.println(dp[n]); } } }