[Huawei OJ] weighing weights

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.