题解 | #称砝码#

#include <bits/stdc++.h>

using namespace std;

int main(){
    int typeNum = 0;
    cin >> typeNum;
    vector<int> weight(typeNum, 0);
    for(int i = 0; i < typeNum; i++){
        int tmp = 0;
        cin >> tmp;
        weight[i] = tmp;
    }
    vector<int> nums(typeNum, 0);
    for(int i = 0; i < typeNum; i++){
        int tmp = 0;
        cin >> tmp;
        nums[i] = tmp;
    }
    
    unordered_set<int> s;
    s.insert(0); //
    for(int i = 0; i < typeNum; i++){//对于每一种砝码
        for(int j = 0; j < nums[i]; j++){//用完当前砝码的数量之前
            unordered_set<int> tmp(s);
            for(auto iter = tmp.begin(); iter != tmp.end(); iter++){//当前集合每个都可以加一次
                s.insert(*iter + weight[i]);
            }
        }
    }
    
    cout << s.size() << endl;
    
    return 0;
}
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务