题解 | #称砝码#
称砝码
http://www.nowcoder.com/practice/f9a4c19050fc477e9e27eb75f3bfd49c
暴力解法,set去重,一会儿去看看大佬们的思路
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
while(cin>>n){
vector<int> m;
vector<int> x;
int a,b;
for(int i=0;i<n;++i){
cin>>a; m.push_back(a);
}
for(int i=0;i<n;++i){
cin>>b; x.push_back(b);
}
set<int> s;
s.insert(0);
for(int i=0;i<n;i++){
for(int j=0;j<x[i];++j){
set<int> tmps;
for(auto it=s.begin();it!=s.end();++it)
{
tmps.insert(*it+m[i]);
}
for(auto it=tmps.begin();it!=tmps.end();++it)
s.insert(*it);
}
}
cout<<s.size()<<endl;
}
return 0;
}