Special Subset Sums: Optimum
Let S(A) denote the sum of elements in a set A of positive integers. We call A a special sum set if for any two non-empty disjoint subsets B, C subseteq A: 1. S(B)!= S(C) (distinct subset sums). 2....
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) \neq S(C)\); that is, sums of subsets cannot be equal.
- 2.
- If \(B\) contains more elements than \(C\) then \(S(B) > S(C)\).
If \(S(A)\) is minimised for a given \(n\), we shall call it an optimum special sum set. The first five optimum special sum sets are given below. \begin {align*} 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\} \end {align*}
It seems that for a given optimum set, \(A = \{a_1, a_2, \dots , a_n\}\), the next optimum set is of the form \(B = \{b, a_1 + b, a_2 + b, \dots , a_n + b\}\), where \(b\) is the "middle" element on the previous row.
By applying this "rule" we would expect the optimum set for \(n = 6\) to be \(A = \{11, 17, 20, 22, 23, 24\}\), with \(S(A) = 117\). However, this is not the optimum set, as we have merely applied an algorithm to provide a near optimum set. The optimum set for \(n = 6\) is \(A = \{11, 18, 19, 20, 22, 25\}\), with \(S(A) = 115\) and corresponding set string: 111819202225.
Given that \(A\) is an optimum special sum set for \(n = 7\), find its set string.
Note: This problem is related to Problem 105 and Problem 106.
Problem 103: Special Subset Sums: Optimum
Mathematical Development
Theorem 1 (Equivalent Condition for Property 2). Let be a set of positive integers. Property 2 holds if and only if
Proof. () Take and . These are disjoint since for . Since , Property 2 yields .
() Let be disjoint subsets of with . Write and . Since the are distinct elements of , we have , so . Similarly, since the are distinct elements of , we have , so . Applying the hypothesis with :
Theorem 2 (Reduction to Global Subset-Sum Uniqueness). Property 1 holds for if and only if all non-empty subset sums of are pairwise distinct.
Proof. () If all subset sums are distinct, then in particular for any two distinct non-empty subsets, a fortiori for disjoint ones.
() We prove the contrapositive. Suppose distinct non-empty subsets satisfy . Let , , . Then and are disjoint. Since , at least one of is non-empty. If both are non-empty, then
violating Property 1. If exactly one (say ) is empty, then and forces ; but all elements are positive, so , contradicting .
Lemma 1 (Near-Optimum Heuristic Construction). Given an optimal special sum set of size with middle element where , the set is a near-optimum special sum set of size .
Proof. This construction, due to Lunnon, yields a set satisfying both properties. The minimum element is , ensuring positivity. Property 2 is satisfied because the spread vs.\ inherits the structure of the original set. Optimality is not guaranteed, but the set serves as a starting point for local search.
Editorial
We check Property 2. Finally, check Property 1. Candidates are generated from the derived formulas, filtered by the required conditions, and processed in order until the desired value is obtained.
Pseudocode
Check Property 2
Check Property 1
Complexity Analysis
- Time. The perturbation space has candidates. For each candidate passing the sum bound and Property 2 filter, Property 1 costs with , i.e., 128 subset-sum computations. With aggressive pruning, total work is on the order of operations.
- Space. for the hash set of subset sums.
Answer
Code
Each problem page includes the exact C++ and Python source files from the local archive.
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
using namespace std;
/*
* Problem 103: Special Subset Sums: Optimum
*
* Search for the optimal n=7 special sum set by perturbing the
* near-optimum {20,31,38,39,40,42,45} by +/-3 on each element.
*/
bool is_special(vector<int>& a) {
int n = a.size();
sort(a.begin(), a.end());
// Property 2
for (int k = 1; k <= n / 2; k++) {
int lo = 0, hi = 0;
for (int i = 0; i <= k; i++) lo += a[i];
for (int i = 0; i < k; i++) hi += a[n - 1 - i];
if (lo <= hi) return false;
}
// Property 1
set<int> sums;
for (int mask = 1; mask < (1 << n); mask++) {
int s = 0;
for (int i = 0; i < n; i++)
if (mask & (1 << i)) s += a[i];
if (sums.count(s)) return false;
sums.insert(s);
}
return true;
}
int main() {
int base[] = {20, 31, 38, 39, 40, 42, 45};
int best_sum = 255;
vector<int> best_set(base, base + 7);
const int D = 3;
for (int d0 = -D; d0 <= D; d0++)
for (int d1 = -D; d1 <= D; d1++)
for (int d2 = -D; d2 <= D; d2++)
for (int d3 = -D; d3 <= D; d3++)
for (int d4 = -D; d4 <= D; d4++)
for (int d5 = -D; d5 <= D; d5++)
for (int d6 = -D; d6 <= D; d6++) {
vector<int> a = {
base[0]+d0, base[1]+d1, base[2]+d2, base[3]+d3,
base[4]+d4, base[5]+d5, base[6]+d6
};
bool ok = true;
for (int x : a) if (x <= 0) { ok = false; break; }
if (!ok) continue;
sort(a.begin(), a.end());
for (int i = 1; i < 7; i++)
if (a[i] <= a[i-1]) { ok = false; break; }
if (!ok) continue;
int s = 0;
for (int x : a) s += x;
if (s > best_sum) continue;
if (is_special(a)) {
if (s < best_sum || (s == best_sum && a < best_set)) {
best_sum = s;
best_set = a;
}
}
}
sort(best_set.begin(), best_set.end());
string ans;
for (int x : best_set) ans += to_string(x);
cout << ans << endl;
return 0;
}
"""
Problem 103: Special Subset Sums: Optimum
Find the optimum special sum set of size 7, starting from the
near-optimum {20, 31, 38, 39, 40, 42, 45}.
"""
from itertools import product
def is_special_sum_set(a):
a = sorted(a)
n = len(a)
# Property 2: sum of smallest k+1 > sum of largest k
for k in range(1, n // 2 + 1):
if sum(a[:k + 1]) <= sum(a[n - k:]):
return False
# Property 1: all subset sums distinct
sums = set()
for mask in range(1, 1 << n):
s = sum(a[i] for i in range(n) if mask & (1 << i))
if s in sums:
return False
sums.add(s)
return True
def solve():
base = [20, 31, 38, 39, 40, 42, 45]
best_sum = sum(base)
best_set = tuple(sorted(base))
delta = 3
for d in product(range(-delta, delta + 1), repeat=7):
a = [base[i] + d[i] for i in range(7)]
if any(x <= 0 for x in a):
continue
a_sorted = sorted(a)
if len(set(a_sorted)) != 7:
continue
s = sum(a_sorted)
if s > best_sum:
continue
if is_special_sum_set(a_sorted):
if s < best_sum or (s == best_sum and tuple(a_sorted) < best_set):
best_sum = s
best_set = tuple(a_sorted)
return "".join(str(x) for x in best_set)
if __name__ == "__main__":
answer = solve()
print(answer)
assert answer == "20313839404245"