Given a set A={a1,a2,…,a of positive integers, find every subset A′⊂A whose sum equals the sum of its complement:
Count and print all such subsets. The bounds are and .
The input consists of multiple datasets, followed by a line which contains only a single ‘.’ (period). Each dataset is an array of unsigned integers. The array is enclosed by {} and any two adjacent unsigned integers of the array are separated with a space.
For each input dataset, print “No such subset” if the input set contains no subsets which meet the criterion. If the input set can be divided into desired subsets, print the number of such subsets first and then print each of those subsets. Print the subsets sorted with number of elements and values of smallest elements in ascending order (subset with fewer elements printed first, and if number of elements are equal, compare the subsequent successor elements). Each subset is enclosed by {} and printed in one line and any two adjacent positive integers in the subset are separated with a space, with elements in increasing order. Each case is separated with a blank line. Follow the format of the sample output.
The input set contains distinct positive integers. On this platform, each input file contains at most50 datasets and the total number of answer subsets across all datasets is at most10000. The original bounds n<=30 and each value<=10^12 remain unchanged. A subset and its complement are counted separately. This output-size guarantee is an explicit platform restriction, introduced after capacity testing; inputs requiring millions of output lines are outside this local specification.
範例輸入 1
{1 2 3 4 5 6 7}
{1 3 5 7 12}
.
範例輸出 1
8 subsets.
{1 6 7}
{2 5 7}
{3 4 7}
{3 5 6}
{1 2 4 7}
{1 2 5 6}
{1 3 4 6}
{2 3 4 5}
No such subset
Pro 專屬功能: 查看這題在歷屆 CPE 出現過幾次 — 升級以解鎖.