Let S (A) be the sum of the elements of the set A of size n. We will call this set a special total set if for any two non-empty and disjoint subsets B and C the following is true:
S (B) ≠ S (C); those. sums of elements of subsets cannot be equal. If B contains more elements than C, then S (B)> S (C). For this problem, we assume that this set consists of n strictly increasing elements and it already complies with the second rule.
Surprisingly, out of 25 possible pairs of subsets that can be obtained from the set with n = 4, only one of them should be checked for equality (the first condition). Similarly, with n = 7, only 70 out of 966 pairs of subsets should be checked for equality.
How many pairs of subsets need to be checked for equality from the total number of 261625 pairs that can be formed with n = 12?
Note: This task is also related to tasks №103 and №105.
Here are some special sets for the first initial n:
n = 1: {1}
n = 2: {1, 2}
n = 3: {2, 3, 4}
n = 4: {3, 5, 6, 7}
n = 5: {6, 9, 11, 12, 13}
My question is as follows. For n = 4, there really are 25 possible unique pairs of non-empty sets. I agree with this. I do not understand why checking for 1 condition requires only one.
If I think correctly, the fulfillment of the second condition is checked only for the case when the sizes of the sets are different. If the second condition is satisfied, then check 1 of the condition is passed automatically. It is obvious.
However, if we eliminate a pair of equal size from 25 variants, then it turns out not 1 pair, but 9. Why for n = 4 in the problem is only 1 pair checked for equality ?!
Just in case, I’ll give my code for searching pairs of subsets:
import itertools a = [3, 5, 6, 7] combinations = set() pair_combinations = list() for b in range(1, len(a)): combinations.update(itertools.combinations(a, b)) combinations = list(combinations) combinations.sort() num = 0 for b in combinations: b_ = list(combinations) b_.remove(b) for с in b_: sum_b = sum(b) sum_c = sum(с) len_set_b = len(list(b)) len_set_c = len(list(с)) set_b = set(b) set_c = set(с) # определяем непересекающиеся подмножества и проводим над ними проверку по условию if set_b.isdisjoint(set_c): # проверка, чтобы не дублировать пары if [с, b] not in pair_combinations: # if len_set_b == len_set_c: pair_combinations.append([b, с]) num = 0 for pair in pair_combinations: print(num, pair) num = num + 1