题解 | #放苹果#
放苹果
https://www.nowcoder.com/practice/bfd8234bb5e84be0b493656e390bdebf
m,n = list(map(int,input().split())) nums = list(range(m+1)) res = 0 def backtrack(start, path, target): global res if len(path)==n and target==0: #res.append(path[:]) res +=1 return elif len(path)==n: return for i in range(start,m+1): num = nums[i] if num > target: break path.append(num) backtrack(i,path,target-num) path.pop() backtrack(0, [], m) print(res)用的回溯