题解 | #称砝码#

称砝码

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

#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_set>
using namespace std;

struct dp{
    int value;
    vector<int> arr;
};

int main(){
    int n;
    cin >> n;
    int temp, num;
    vector<int> weight1Arr, num1Arr, all;
    for(int i = 1; i <= n; i++){
        cin >> temp;
        weight1Arr.push_back(temp);
    }
    for(int i = 1; i <= n; i++){
        cin >> temp;
        num1Arr.push_back(temp);
    }
    num = weight1Arr.size();
    for(int i = 0; i < num;i++){
        for(int j = 0; j < num1Arr.back(); j++){
            all.push_back(weight1Arr.back());
        }
        num1Arr.pop_back();
        weight1Arr.pop_back();
    }
    unordered_set<int> ans;
    ans.insert(0);
    for(int i = 0; i < all.size(); i++){
        unordered_set<int> temp(ans);
        unordered_set<int>::iterator iter;
        for(iter = temp.begin(); iter != temp.end(); iter++){
            ans.insert(*iter + all[i]);
        }
    }
    cout << ans.size();
    return 0;
}

全部评论

相关推荐

友友们,我实在是不太明白,校招的话现在大多也是提前实习,然后转正也是需要考核的,考核通过才能转正,那这跟实习转正有什么区别啊
苦闷的仰泳鲈鱼刷了1...:提前实习,是让你提前熟悉业务的,后续是入职后可以减少试用期的(大部分是包入职的);转正实习,要是hc不够或者其他原因,让你正式offer可能都没有,这个风险很大。 ---个人看法和了解到的。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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