From 1043b7740efd324cdfa53655cd897bb16ec4d159 Mon Sep 17 00:00:00 2001 From: Echo0701 <133868458+Echo0701@users.noreply.github.com> Date: Tue, 28 Nov 2023 21:51:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B00070.=E7=88=AC=E6=A5=BC?= =?UTF-8?q?=E6=A2=AF=E5=AE=8C=E5=85=A8=E8=83=8C=E5=8C=85=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E7=9A=84=20Java=20=E8=AF=AD=E8=A8=80=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0070.爬楼梯完全背包版本.md | 24 ++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/problems/0070.爬楼梯完全背包版本.md b/problems/0070.爬楼梯完全背包版本.md index 26af2569..93a336ab 100644 --- a/problems/0070.爬楼梯完全背包版本.md +++ b/problems/0070.爬楼梯完全背包版本.md @@ -139,6 +139,30 @@ int main() { ### Java: +```Java +import java.util.Scanner; +class climbStairs{ + public static void main(String [] args){ + Scanner sc=new Scanner(System.in); + int m, n; + while(sc.hasNextInt()){ + // 从键盘输入参数,中间用空格隔开 + n = sc.nextInt(); + m = sc.nextInt(); + + // 求排列问题,先遍历背包再遍历物品 + int[] dp = new int[n + 1]; + dp[0] = 1; + for (int j = 1; j <= n; j++) { + for (int i = 1; i <= m; i++) { + if (j - i >= 0) dp[j] += dp[j - i]; + } + } + System.out.println(dp[n]); + } + } +} +``` ### Python3: