题解 | #称砝码#
称砝码
https://www.nowcoder.com/practice/f9a4c19050fc477e9e27eb75f3bfd49c
#include <iostream>
#include <vector>
#include <unordered_set>
using namespace std;
int main(int argc, char* argv[]){
int n;
cin >> n;
vector<int> weights(n, 0);
for(int i = 0; i < n; ++i){
cin >> weights[i];
}
vector<int> amounts(n , 0);
for(int i = 0; i < n; ++i){
cin >> amounts[i];
}
unordered_set<int> kinds;
kinds.insert(0);
for(int i = 0; i < weights.size(); ++i){
for(int j = 1; j <= amounts[i]; ++j){
unordered_set<int> temp(kinds);
for(auto iter = temp.begin(); iter != temp.end(); ++iter){
kinds.insert(*iter + weights[i]);
}
}
}
cout << kinds.size() << endl;
return 0;
}