大佬可以帮忙看下为什么0-1背包那一题只过了40%吗? n, m = list(map(int, input().split())) costs = [] profits = [] # print(n) (9255)# print(m) for i in range(n): a, b = list(map(int, input().split())) if a <= m: costs.append(a) profits.append(b) dp = [0]*(m+1) for i in range(1, n): # print(costs[i]) for v in range(m, costs[i], -1): cost = costs[i] profit = profits[i] dp[v] = max(dp[v], dp[v-cost]+profits[i]) print(dp[-1])
点赞 4

相关推荐

AFBUFYGRFHJLP:直接去美帝试试看全奖phd吧
点赞 评论 收藏
分享
有趣的牛油果开挂了:最近这个阶段收到些杂七杂八的短信是真的烦
点赞 评论 收藏
分享
牛客网
牛客企业服务