题解 | #购物单#

购物单

https://www.nowcoder.com/practice/f9c6f980eeec43ef85be20755ddbeaf4

n, m = map(int, input().split())
n = n // 10
w_dict, v_dict, fwv_list = {}, {}, []
for i in range(1, m + 1):
    v, p, q = map(int, input().split())
    v = v // 10
    if q == 0:
        w_dict[i] = [v]
        v_dict[i] = [v * p]
    else:
        fwv_list.append([q, v, v * p])

for q, w, v in fwv_list:
    for index in range(len(w_dict[q])):
        w_dict[q].append(w_dict[q][index] + w)
    for index in range(len(v_dict[q])):
        v_dict[q].append(v_dict[q][index] + v)

w_list, v_list = [[0]]+list(w_dict.values()), [[0]]+list(v_dict.values())
mm = len(w_dict)
dp = [[0] * (n + 1) for _ in range(mm + 1)]
for i in range(1, mm + 1):
    for j in range(1, n + 1):
        tw = dp[i - 1][j]
        for k in range(len(w_list[i])):
            if j >= w_list[i][k]:
                tw = max(tw, dp[i - 1][j - w_list[i][k]] + v_list[i][k])
        dp[i][j] = tw
print(max(max([i for i in dp])) * 10)

全部评论

相关推荐

蚂蚁 基架java (n+6)*16 签字费若干
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
09-30 19:49
起名星人:蛮离谱的,直接要求转投销售
投递汇川技术等公司10个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务