POJ Sticks Stick Enumeration + search + Tips

Source: Internet
Author: User

This is probably I have seen before the title, at that time I was not very able to hit the search, and even think that the efficiency of the enumeration is very low, is not able to put the topic AC, and later in order to change this view (in fact, I found some of the problems I can not think of the AC program most have search, enumeration algorithm, especially Never thought it would be so simple). To do a few search questions. This is one of the problems that I worried about in those years, can't think of, go to Baidu, so simple, heart-broken. Indeed search if the pruning done well, it is possible to put some of the topics AC.

All right! Can be finished after the submission of the first time or tle, the heart is very tired. To other people's blog park to see a bit, in fact, everyone is similar. A careful look only found that others are descending, and I am ascending. This is an estimate of the problem is a little tricks it! After the end, AC, since the experience in this, accumulate it, after all, add up.

1#include <cstdio>2#include <iostream>3#include <algorithm>4#include <cstring>5#include <Set>6 #defineMAXN 707 #defineRep (i,j,k) for (int i = j; I <= K; i++)8 #defineSt Stick[i]9 using namespacestd;Ten  One intSTICK[MAXN] = {0}, N, used[maxn] = {0}, ch, mu; A intUNABLE[MAXN] = {0}; -  - BOOLBmpintAintb) the { -     returnA >b; - } -  +InlineintRead () - { +     ints =0, t =1; A     Charc =GetChar (); at      while( !IsDigit (c)) { -         if(c = ='-') T =-1; -c =GetChar (); -     }  -      while(IsDigit (c)) { -s = S *Ten+ C-'0'; inc =GetChar (); -     } to     returnS *T; + } -  the BOOLMatchintShengintXintci) * { $     if(!sheng) ci++, x =0, Sheng =ch;Panax Notoginseng     if(ci = = mu)return 1; -Rep (i,x,n-1){ the         if(St <= sheng &&!)Used[i]) { +Used[i] =1; A             if(Match (sheng-st,i+1, CI))return 1; the             Else if(x = =0 )  { +Used[i] =0;return 0; -             }  $Used[i] =0; $             intj = i; while(stick[j+1] = = Stick[i]) j + +; i =J; -         } -     } the     return 0; - }Wuyi  the intMain () - { Wu N; -      while(SCANF ("%d", &n) = =1&&N) { About         intsum =0; $Rep (I,0, N-1){ -St =read (); -Sum + =St; -Used[i] =0; A         } +Sort (stick,stick+n,bmp); the         intMAXL = stick[0];  - Rep (i,maxl,sum) { $             if(sum% i = =0 ){ theCH =i; themu = SUM/i; the                 if(Match (I,0,0) ){ thecout<<i<<Endl; -                      Break; in                 }  the             } the         } About     } the     return 0; the}

POJ Sticks Stick Enumeration + search + Tips

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.