题解 | #放苹果#

放苹果

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)
用的回溯
全部评论

相关推荐

牛客51274894...:照片认真的吗,找个专门拍证件照的几十块钱整端正点吧,要不就别加照片
点赞 评论 收藏
分享
03-31 00:39
门头沟学院 C++
南岗痞子:不还有俩没结束吗
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务