AcWing
  • 首页
  • 课程
  • 题库
  • 更多
    • 竞赛
    • 题解
    • 分享
    • 问答
    • 应用
    • 校园
  • 关闭
    历史记录
    清除记录
    猜你想搜
    AcWing热点
  • App
  • 登录/注册

AcWing 6. 多重背包问题 III    原题链接    困难

作者: 作者的头像   华烬 ,  2025-06-10 17:32:45 · 江苏 ,  所有人可见 ,  阅读 2


0


[//]: # 二进制枚举优化

蓝桥杯的课先写过金明那题,遂优化,发现能过,O(NMlogS)的样子

n, m = map(int, input().split())
dp = [0] * (m + 1)

for _ in range(n):
    v, w, s = map(int, input().split())
    k = 1
    while k <= s:
        current_v = k * v
        current_w = k * w
        for j in range(m, current_v - 1, -1):
            dp[j] = max(dp[j], dp[j - current_v] + current_w)
        s -= k
        k *= 2
    if s > 0:
        current_v = s * v
        current_w = s * w
        for j in range(m, current_v - 1, -1):
            dp[j] = max(dp[j], dp[j - current_v] + current_w)

print(dp[m])

0 评论

App 内打开
你确定删除吗?
1024
x

© 2018-2025 AcWing 版权所有  |  京ICP备2021015969号-2
用户协议  |  隐私政策  |  常见问题  |  联系我们
AcWing
请输入登录信息
更多登录方式: 微信图标 qq图标 qq图标
请输入绑定的邮箱地址
请输入注册信息