题解 | #称砝码#
称砝码
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;
}
汤臣倍健公司氛围 401人发布