题解 | #放苹果#
放苹果
https://www.nowcoder.com/practice/bfd8234bb5e84be0b493656e390bdebf
def count_ways(m, n): dp = [[0 for _ in range(n + 1)] for _ in range(m + 1)] # 初始化边界条件 for i in range(n + 1): dp[0][i] = 1 # 没有苹果,分法只有1种 for i in range(1, m + 1): dp[i][1] = 1 # 只有一个盘子,分法只有1种 # 填充dp表 for i in range(1, m + 1): for j in range(2, n + 1): if j > i: dp[i][j] = dp[i][i] else: dp[i][j] = dp[i][j - 1] + dp[i - j][j] return dp[m][n] # 读取输入 input_str = input() m, n = map(int, input_str.split()) # 计算并输出结果 print(count_ways(m, n))