mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 03:34:02 +08:00
更新0070.爬楼梯完全背包版本的 Java 语言版本
This commit is contained in:
@ -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:
|
||||
|
||||
|
Reference in New Issue
Block a user