2016HUAS_ACM Summer Camp 4K-Basic DP

Source: Internet
Author: User

I don't know how to use DP, but DFS is very useful. The DFS idea is obvious, search, record, if just find half of the total value of the search to indicate success.

The main topic: 6 numbers per group, representing the number of items worth 1 to 6 respectively. Now ask if you can divide it by value.

Sample Input//6 The number of value items, all at 0 o'clock end

1 0 1 2 0 0

1 0 0 0 1 1

0 0 0 0 0 0

Sample Output//Note format, empty two lines

Collection #1: Can ' t be divided.

Collection #2: Can be divided.

1#include <iostream>2 using namespacestd;3 4 intn[7];//Storage Quantity5 intsum,t=1, I;6 BOOLFlag//Mark7 8 voidDfsintSintp)9 {Ten     if(s==sum/2)//found the value of just half One     { Aflag=true; -         return; -     } the      for(inti=p;i>=1; i--)//search, looks like a DP. -     { -         if(N[i]) -         { +             if(s+i<=sum/2) -             { +n[i]--; ADFS (s+i,i); at                 if(flag) -                      Break; -             } -         } -     } -     return; in } -  to  + intMain () - { the      while(1) *     { $sum=0;Panax Notoginseng          for(i=1; i<=6; i++) -         { theCin>>N[i]; +Sum+=i*n[i];//figure out the sum of values A         } the         if(! Sum)//all 0 +              Break; -         if(sum%2)//The total value is odd when not established, pruning $         { $cout<<"Collection #"<<T<<": \ncan ' t be divided.\n\n"; -t++; -             Continue; the         } - Wuyiflag=false; the  -Dfs0,6); Wu  -         if(flag) About         { $cout<<"Collection #"<<T<<": \ncan be divided.\n\n"; -t++; -             Continue; -         } A         Else +         { thecout<<"Collection #"<<T<<": \ncan ' t be divided.\n\n"; -t++; $             Continue; the         } the     } the     return 0; the}
View Code

2016HUAS_ACM Summer Camp 4K-Basic DP

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.