题解 | #称砝码#

称砝码

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

//
// Created by Dell on 2024/3/27.
//
#include <iostream>
#include <unordered_set>
#include <vector>

using namespace std;

int main() {
    int n;
    while (cin >> n) {
        vector<int> weight(n);
        vector<int> num(n);
        for (int i = 0; i < n; i++) {
            cin >> weight[i];
        }
        for (int i = 0; i < n; i++) {
            cin >> num[i];
        }
        unordered_set<int> s;
        s.insert(0);
        for (int i = 0; i < n; i++) {
            for (int j = 1; j <= num[i]; j++) {
                unordered_set<int> temp(s);
                for (auto it = temp.begin(); it != temp.end(); it++) {
                    s.insert(*it + weight[i]);
                }

            }
        }
        cout << s.size() << endl;

    }
    return 0;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

求offer的大角牛:不吃香菜
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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