Python题解 | #称砝码#

称砝码

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

import sys

n = int(input())
weight = list(map(int, input().strip().split(' ')))
num = list(map(int, input().strip().split(' ')))
sum_w = 0

for i in range(n):
    sum_w += weight[i] * num[i]

dp = [0] * (sum_w + 1)
dp[0] = 1
ans = 1
for i in range(n):
    for j in range(num[i]):
        ans |= ans << weight[i]
print(bin(ans).count('1'))

全部评论

相关推荐

Clavoss:一眼AI,死亏
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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