pub fn restricted_partition_count(
n: u64,
k: u64,
block_min: u64,
block_max: u64,
) -> Result<u64, CombinatoricsError>Expand description
Count ways to partition n labelled elements into exactly k unlabelled, non-empty blocks,
each block’s size restricted to [block_min, block_max].
Generalises stirling_second_kind (which is the block_min = 1, block_max = n case) to a
bounded block size, needed for a partition domain’s own numParts/partSize attributes.
§Method
Builds each partition by always placing the smallest not-yet-placed element into a fresh
block, then choosing the rest of that block’s members from the remaining elements – this
canonical “root by smallest element” construction counts each unordered partition exactly
once, unlike naively assigning elements to numbered blocks (which overcounts by the blocks’
own arbitrary ordering). Recurrence, with g(n, k) counting n elements into k blocks:
g(0, 0) = 1, g(n, 0) = 0 for n > 0, g(0, k) = 0 for k > 0, and for n, k > 0:
g(n, k) = sum_{s=block_min}^{min(block_max, n)} C(n-1, s-1) * g(n-s, k-1)
(choose s, the size of the block containing the smallest remaining element, then its other
s-1 members from the other n-1 elements).