HDU 1455 -- Sticks (stick)

Source: Internet
Author: User

HDU 1455 -- Sticks (stick)

This is similar to HDU1518.


Attach test data ~~


64
40 40 30 35 26 15 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40
40 40 43 42 41 10 4 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40
40 25 39 46 40 10 40 40 37 18 17 16 15 40 40 40 40 40 40 40


46
40 37 32 10 47 4 42 56 61 23 36 27 16 16 26 19 14 29 31 58 51 32 63 28 11 25 12 15 39 42 46 11 19 53 17 39 21 45 44 8 23 51 55


58
57 6 44 4 16 35 54 9 32 23 43 55 46 41 8 41 44 31 59 58 59 29 53 30 3 39 17 32 45 8 40 34 18 20 11 32 33 14 41 31 25 4 42 54 9 29 37 47 29 34 20 47 56 61 5


26
3 64 18 49 4 40 18 61 50 36 17 8 17 62 11 24 8 36 59 34 26 28 7 37 26


12
1 1 2 2 2 3 3 3 3 3 4


27
15 3 2 4 11 1 8 8 8 15 3 2 4 11 1 8 8 15 3 2 4 11 1 8 8


9
15 4 3 1 2 8 11 8


45
15 3 2 11 4 1 8 8 8 15 3 2 11 4 8 8 8 15 3 2 11 4 1 8 8 8 15 3 2 11 4 1 8 8 8
15 3 2 11 4 1 8 8 8
0


Answer:

454
89
89
99
6
20
20
20


# Include
 
  
# Include
  
   
# Include
   
    
# Include
    
     
# Define M 100 using namespace std; int n, m, sum, flag, vis [M], a [M]; void dfs (int s, int cur, int d, int p, int q) {if (cur = p | flag) {flag = 1; return;} for (int I = s; I
     
      
Q) continue; vis [I] = 1; if (d + a [I] = q) dfs (0, cur + 1, 0, p, q ); else dfs (I + 1, cur, d + a [I], p, q); vis [I] = 0; if (flag) return; if (d = 0) break; // pruning while (a [I + 1] = a [I]) I ++; // if the property is the same, pruning} return;} int main () {// freopen ("input.txt", "r", stdin); // freopen ("output.txt", "w", stdout ); while (scanf ("% d", & n), n) {sum = 0; for (int I = 0; I
      
        (); For (int I = a [0]; I <= sum; ++ I) {if (sum % I) continue; memset (vis, 0, sizeof vis); flag = 0; dfs (0, 0, sum/I, I); if (flag) {cout <
       
        

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.