题解 | #称砝码#

称砝码

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

#include <bits/stdc++.h>
using namespace std;

int main() {
    int n;
    cin >> n;
    int weight[n], num[n];
    for (int i = 0; i < n; i++) {
        cin >> weight[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> num[i];
    }

    set<int> st1;
    st1.insert(0);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < num[i]; j++) {
            set<int> st2(st1);
            for (auto iter = st2.begin(); iter != st2.end(); iter++) {
                st1.insert(*iter + weight[i]);
            }
        }
    }
    cout << st1.size()<< endl;
}

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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