The algorithm itself is very inefficient, but the feeling is relatively concise, so I recorded the next. Huawei's Test cases only one, passed through, but feel that there is no way to check the correctness of this procedure, the individual feel logically correct.
1#include <iostream>2#include <Set>3#include <algorithm>4 5 using namespacestd;6 7 intFamaintNint* Weight,int*nums)8 {9 Set<int>Setint;TenSetint.insert (0); One for(intI=0; i<n;i++) A { - intw=Weight[i]; - Set<int>settemp; the Set<int>::iterator bitr=Setint.begin (); - Set<int>::iterator eitr=setint.end (); - for(Set<int>::iterator p=bitr;p!=eitr;p++) - { + intwt=*p; - for(intCount=0; count<=nums[i];count++) + { A inttwt=wt+w*count; at Settemp.insert (TWT); - } - } - Setint.insert (Settemp.begin (), Settemp.end ()); - } - returnstatic_cast<int>(Setint.size ()); in } - to intMain () + { - int*weight; the int*nums; * intN; $Cin>>N;Panax Notoginseng -weight=New int[n]; thenums=New int[n]; + A for(intI=0; i<n;i++) theCin>>Weight[i]; + - for(intI=0; i<n;i++) $Cin>>Nums[i]; $ -Cout<<fama (n,weight,nums) <<Endl; - the}
[Huawei OJ] weighing weights