An algorithm for the set of subsets with equal sums of a set of numbers (distinct partitions)

113 Views Asked by At

Given a set $T\subset\mathbb N^+$ called the set of terms and let $T_n=\{k\in T|k\leq n\}$. I want to design an efficient algorithm computing the set $\mathcal S_n$ of all subsets $S\subseteq T$ such that $n=\sum_{m\in S} m$, for $n\in \mathbb N$. With efficient I mean significantly faster than calculating the set of all subsets of $T_n$ and check the sums.

There seems to be a rule of recursion $$\mathcal S_n=\bigcup_{t\in T}\mathcal f(S_{n-t},t)$$ for $n\neq 2t$ (for some $t\in T$), where $f(X,x)=\{A|\exists B\in X:A=B\cup \{x\}\}$. But I can't grasp the terminal cases for a recursive algorithm. "Natural" terminal cases, in my opinion, are $n\in T$ such that $|\mathcal S_n|=1$, but those terms are unknown initially.

Is there a reasonable solution to this problem?

1

There are 1 best solutions below

0
On

No. You can count such subsets reasonably efficiently using dynamic programming, but the number of such subsets can be exponential in the size of $T$. Consider, for example, $T = \{1, 2, \ldots, 2u\}$. It contains $u$ pairs of sum $u+1$, so if we have $n = (u+1)\lfloor \frac u 2 \rfloor$ then that gives a lower bound of $\binom{u}{\lfloor u / 2 \rfloor}$ subsets.