题解 | #点菜问题#

点菜问题

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

while True:
    try:
        m, n = map(int, input().split(" "))
        w = [0 for i in range(n)]  # 钱大小
        v = [0 for i in range(n)]  # 分数
        dp = [0 for i in range(m + 1)]
        for i in range(n):
            w[i], v[i] = map(int, input().split(" "))
        for i in range(n):
            for j in range(m, w[i] - 1, -1):
                dp[j] = max(dp[j], dp[j - w[i]] + v[i])
        print(dp.pop())
    except:
        break

全部评论

相关推荐

10-10 17:54
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务