Special Subset Sums: Meta-testing
Let S(A) represent the sum of elements in set A of size n. We shall call it a special sum set if for any two non-empty disjoint subsets, B and C, the following properties are true: 1. S(B)!= S(C);...
Problem Statement
This archive keeps the full statement, math, and original media on the page.
Let \(S(A)\) represent the sum of elements in set \(A\) of size \(n\). We shall call it a special sum set if for any two non-empty disjoint subsets, \(B\) and \(C\), the following properties are true:
- 1.
- \(S(B) \ne S(C)\); that is, sums of subsets cannot be equal.
- 2.
- If \(B\) contains more elements than \(C\) then \(S(B) \gt S(C)\).
For this problem we shall assume that a given set contains \(n\) strictly increasing elements and it already satisfies the second rule.
Surprisingly, out of the \(25\) possible subset pairs that can be obtained from a set for which \(n = 4\), only \(1\) of these pairs need to be tested for equality (first rule). Similarly, when \(n = 7\), only \(70\) out of the \(966\) subset pairs need to be tested.
For \(n = 12\), how many of the \(261625\) subset pairs that can be obtained need to be tested for equality?
Note: This problem is related to Problem 103 and Problem 105.
Problem 106: Special Subset Sums: Meta-testing
Mathematical Foundation
Theorem 1. (Reduction to Equal-Size Pairs) If Property 2 holds for a set , then for all non-empty disjoint subsets with .
Proof. Without loss of generality, assume . Property 2 directly gives , hence .
Theorem 2. (Counting Equal-Size Disjoint Pairs) The number of unordered pairs of disjoint subsets of an -element set with is:
Proof. To choose an ordered pair : first choose as any -subset of in ways, then choose as any -subset of the remaining elements in ways. This counts each unordered pair twice (once as and once as ), so .
For the alternative form: first choose the elements that will participate in ways, then partition them into two groups of in ways (dividing by 2 for the unordered pair).
Theorem 3. (Non-Crossing Pairs are Automatically Verified) Let satisfy Property 2. Consider two disjoint subsets with . Sort the elements of as and of as . If for all (or for all ), then is automatically guaranteed.
Proof. Suppose for all . Then , since for every index. Hence without any additional verification. The case for all is symmetric.
Theorem 4. (Connection to Catalan Numbers) Given elements in sorted order, the number of ways to partition them into two groups of such that the element-wise comparison is non-crossing (i.e., for all , or for all , when both sequences are sorted) equals for ordered pairs or for unordered pairs, where is the -th Catalan number.
Proof. Label the sorted elements by their group membership: each element gets label or , with exactly of each. We claim that the partition has the non-crossing property (say for all ) if and only if, when we read the labels in sorted order of the elements, we never have more -labels than -labels in any prefix.
To see this: sort all elements as . Assign -labels and -labels. The sorted -sequence is (the elements labeled in order) and similarly for . The condition for all means that the -th -element appears before the -th -element in the sorted order. This is equivalent to requiring that in every prefix of the label sequence, the count of ‘s is at least the count of ‘s.
The number of such sequences is exactly the -th Catalan number , by the ballot problem / Bertrand ballot theorem. (The total number of label sequences with ‘s and ‘s is , and the fraction with all prefixes having at least as many ‘s as ‘s is .)
For unordered pairs, the non-crossing partitions with are in bijection with the partitions with (swap labels). Each unordered pair is counted once, so the number of unordered non-crossing pairs is .
Theorem 5. (Main Formula) The number of equal-size disjoint pairs that need testing is:
where .
Proof. For each subset size , the total number of unordered equal-size disjoint pairs is (Theorem 2). Of these, are non-crossing and hence automatically verified (Theorems 3-4). The difference gives the number needing testing.
For : , so no singleton pairs need testing (if then trivially ). Hence the sum starts at .
Editorial
|-----|-------------------|-----------------------------|--------|------------|--------------| | 2 | 495 | 3 | 2 | 1 | 495 | | 3 | 924 | 10 | 5 | 5 | 4620 | | 4 | 495 | 35 | 14 | 21 | 10395 | | 5 | 66 | 126 | 42 | 84 | 5544 | | 6 | 1 | 462 | 132 | 330 | 330 |.
Pseudocode
total = 0
For k from 2 to floor(n/2):
choose_2k = binomial(n, 2*k)
half_middle = binomial(2*k, k) / 2
catalan_k = binomial(2*k, k) / (k + 1)
total += choose_2k * (half_middle - catalan_k)
Return total
Computation for :
| Difference | Contribution | ||||
|---|---|---|---|---|---|
| 2 | 495 | 3 | 2 | 1 | 495 |
| 3 | 924 | 10 | 5 | 5 | 4620 |
| 4 | 495 | 35 | 14 | 21 | 10395 |
| 5 | 66 | 126 | 42 | 84 | 5544 |
| 6 | 1 | 462 | 132 | 330 | 330 |
## Complexity Analysis
- **Time**: $O(n)$ to iterate over $k$ values from 2 to $\lfloor n/2 \rfloor$, assuming $O(1)$ computation of binomial coefficients (precomputed or via closed-form). For $n = 12$, this is 5 iterations.
- **Space**: $O(1)$, storing only a running total and temporary values.
## Answer
$$
\boxed{21384}
$$ Code
Each problem page includes the exact C++ and Python source files from the local archive.
#include <bits/stdc++.h>
using namespace std;
// Compute binomial coefficient C(n, k)
long long comb(int n, int k) {
if (k < 0 || k > n) return 0;
if (k == 0 || k == n) return 1;
if (k > n - k) k = n - k;
long long result = 1;
for (int i = 0; i < k; i++) {
result = result * (n - i) / (i + 1);
}
return result;
}
// Catalan number C_k = C(2k,k) / (k+1)
long long catalan(int k) {
return comb(2 * k, k) / (k + 1);
}
int main() {
int n = 12;
long long total = 0;
for (int k = 2; k <= n / 2; k++) {
long long choose_2k = comb(n, 2 * k);
long long half_choose = comb(2 * k, k) / 2;
long long cat_k = catalan(k);
total += choose_2k * (half_choose - cat_k);
}
cout << total << endl;
return 0;
}
"""
Problem 106: Special Subset Sums: Meta-testing
For n=12, count how many subset pairs (B, C) with |B|=|C| need to be
tested for equality, given that the ordering rule already handles |B|!=|C|.
Formula: sum over k=2..n/2 of C(n,2k) * [C(2k,k)/2 - Catalan(k)]
"""
from math import comb
def catalan(k):
"""k-th Catalan number: C(2k,k) / (k+1)"""
return comb(2 * k, k) // (k + 1)
def solve(n=12):
total = 0
for k in range(2, n // 2 + 1):
choose_2k = comb(n, 2 * k)
half_choose = comb(2 * k, k) // 2
cat_k = catalan(k)
contribution = choose_2k * (half_choose - cat_k)
total += contribution
return total
answer = solve(12)
print(answer)