题解 | #放苹果#
放苹果
http://www.nowcoder.com/practice/bfd8234bb5e84be0b493656e390bdebf
"""s = input().split()
m = int(s[0])
n = int(s[1])"""
'''while True:
try:
m,n = map(int, input().split())
dp = [[1 for i in range(n+1)] for i in range(m+1)]
for i in range(m+1):
dp[i][0] = 0
for j in range(1, n+1):
for i in range(1, m+1):
if j > i:
dp[i][j] = dp[i][i]
else:
dp[i][j] = dp[i][j-1] + dp[i-j][j]
print(dp[m][n])
except:
break'''
# 放苹果分两种情况,一种是有盘子为空,一种是每个盘子都有苹果
# 令(m,n)表示将m个苹果放入n个盘子中的摆放方法总数
# 1. 假设有一个盘子为空,则(m,n)问题转化为将m个苹果放在n-1个盘子上,即求得(m, n-1)即可
# 2. 假设所有盘子都装有苹果,则每个盘子至少有一个苹果,即最多剩下m-n个苹果,即问题转化为将m-n个苹果
# 放到n个盘子里,即求(m-n, n)
def f(m,n):
if m < 0 or n < 0:
return 0
elif m == 1 or n == 1:
return 1
else :
return f(m, n-1) + f(m-n, n)
while True:
try:
m, n = map(int, input().split())
print(f(m, n))
except:
break