Dividing
Time limit1sMemory limit128 MB
Given counts of marbles worth 1 to 6, decide whether the collection can be split into two sets of equal total value.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Greedy, Bit manipulation
- Solved
- No attempts yet
Problem
Marsha and Bill jointly own a collection of marbles. They want to split the collection between them so that each receives an equal share.
This would be easy if every marble were worth the same, because then they could just split the collection in half by count. Unfortunately, some marbles are larger or more beautiful than others, so Marsha and Bill assign each marble a value: a natural number between and . Now they want to divide the marbles so that each person gets the same total value.
It may be impossible to divide the marbles this way, even when the total value of all marbles is even. For example, with one marble of value , one of value , and two of value , there is no way to split them into two sets of equal value.
Write a program that decides whether a fair partition of the marbles exists.
Input
Each line of the input describes one collection of marbles to be divided. A line contains six non-negative integers , where is the number of marbles of value . For instance, the collection above is described by the line 1 0 1 2 0 0. The total number of marbles in any collection is at most .
The input ends with a line containing 0 0 0 0 0 0; do not process this line.
Output
For each collection, output Collection #k:, where is the number of the collection (starting from ), and on the next line print either Can be divided. or Can't be divided..
Print a blank line between consecutive collections.