题解 | #称砝码#

称砝码

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

n_weights = int(input())
weights = [int(w) for w in input().split()]
nums = [int(i) for i in input().split()]

# credits to wfj
def count_different_weights(n, weight_lst, count_lst):
    exist_weights = {0}
    for w, c in zip(weight_lst, count_lst):
        need_try_to_add_one = exist_weights
        for i in range(c):
            need_try_to_add_more = []
            for wi in need_try_to_add_one:
                wi += w
                if wi not in exist_weights:
                    need_try_to_add_more.append(wi)
            need_try_to_add_one = need_try_to_add_more
            exist_weights.update(need_try_to_add_one)
    return len(exist_weights)

result = count_different_weights(n_weights, weights, nums)
print(result)

算法学习分析与整理 文章被收录于专栏

个人学习算法的文档整理与思考,举一反三,相爱相杀。

全部评论

相关推荐

那么好了好了:他本来公司就是做这个的,不就是正常的游戏客户端和服务器开发,软硬件联动,有啥恶心不恶心的,提前告诉你就是怕你接受不了,接受不了就没必要再往后走流程浪费时间,虽然这公司是一坨。
点赞 评论 收藏
分享
没有offer的呆呆:薪资有的时候也能说明一些问题,太少了活不活得下去是一方面,感觉学习也有限
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务