HDU 1059 Full Backpack

Source: Internet
Author: User

Dividing

Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 22808 Accepted Submission (s): 6444


Problem Descriptionmarsha and Bill own a collection of marbles. They want to split the collection among themselves so, both receive an equal share of the marbles. This would is easy if all the marbles had the same value, because then they could just split the collection in half. But unfortunately, some of the marbles is larger, or more beautiful than others. So, Marsha and Bill start by assigning a value, a natural number between one and six, to each marble. Now they want to divide the marbles so, each of the them gets the same total value.
Unfortunately, they realize that it might is impossible to divide the marbles on this the-to Marbles is even). For example, if there is one marble of value 1, one of value 3 and both of the value 4, then they cannot is split into sets of Equal value. So, they ask for write a program that checks whether there is a fair partition of the Marbles.

Inputeach line in the input describes one collection of marbles to be divided. The lines consist of six non-negative integers n1, n2, ..., N6, where NI is the number of marbles of value I. So, the example from above would is described by the Input-line ' 1 0 1 2 0 0 '. The maximum total number of marbles would be 20000.

The last line of the input file would be ' 0 0 0 0 0 0 '; Do not process this line.

Outputfor each colletcion, output "Collection #k:", where k is the number of the "the test case" and then either "Can be div ided. ' or ' Can ' t be divided.

Output a blank line after each test case.

Sample INPUT1 0 1 2 0 01 0 0 0 1 10 0 0 0 0 0

Sample outputcollection #1: Can ' t be divided. Collection #2: Can be divided.

Source mid-central European Regional Contest 1999 puzzle: 6 stones have different values now require you to divide the input n1...ni....n6 to represent the value of the stone of I have NI if can equal as required Output and vice versa test instructions: Backpack capacity is half of the total value if you can meet the f[m]==m, it means that the binary optimization can be achieved by dividing the full backpack.
1#include <iostream>2#include <cstring>3#include <cstdio>4#include <algorithm>5 #definell __int646 using namespacestd;7 intn[Ten];8 intm;9 intJishu;Ten intsize[60005]; One intvalue[60005]; A intcoun=1; - intf[60005]; - voidSlove (intq) the { -coun=1; -     for(intI=1; i<=q;i++)  -   {   +      intc=n[i],v=i;  -      for(intk=1; k<=c; k<<=1)  +     {   AValue[coun] = k*v;  atsize[coun++] = k*v;  -C-=K;  -     }   -     if(C >0)   -     {   -Value[coun] = c*v;  insize[coun++] = c*v;  -     }   to }   + } - intMain () the{jishu=0; *      while(SCANF ("%d %d%d%d%d%d", &n[1],&n[2],&n[3],&n[4],&n[5],&n[6])!=EOF) $     {   Panax Notoginseng         if(n[1]==0&&n[2]==0&&n[3]==0&&n[4]==0&&n[5]==0&&n[6]==0) -          Break; theMemset (F,0,sizeof(f)); +memset (Size,0,sizeof(size)); Amemset (Value,0,sizeof(value)); them=n[1]+n[2]*2+n[3]*3+n[4]*4+n[5]*5+n[6]*6; +         if(m%2) -         { $printf"Collection #%d:\ncan ' t be divided.\n\n",++Jishu); $         } -         Else -         {  theSlove (6); -m=m/2;Wuyi              for(intI=1; i<=coun-1; i++) the              for(intk=m;k>=value[i];k--) -             { WuF[k]=max (f[k],f[k-size[i]]+value[i]); -             } About          if(f[m]==m) $printf"Collection #%d:\ncan be divided.\n\n",++Jishu);  -             Else -printf"Collection #%d:\ncan ' t be divided.\n\n",++Jishu); -                  A         } +          the     } -     return 0; $}

HDU 1059 Full Backpack

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.