#P2386. Distribution of Apples into Plates
Distribution of Apples into Plates
Distribution of Apples into Plates
Given m identical apples and n identical plates, where some plates may remain empty, determine the number of distinct ways to distribute the apples among the plates. Note that, for example, the distributions 5, 1, 1 and 1, 1, 5 are considered the same.
This problem is equivalent to finding the number of partitions of m into at most n nonnegative parts. In other words, if we define p(m, n) as the number of partitions of m into at most n parts, it satisfies the recurrence:
\( p(m, n) = p(m, n-1) + p(m-n, n) \)
with the base cases \( p(0, n) = 1 \) for any \( n \) and \( p(m, 1) = 1 \) for \( m \ge 0 \). If \( m < n \), then \( p(m, n) = p(m, m) \).
inputFormat
The input consists of a single line containing two space-separated integers m and n, where m is the number of apples and n is the number of plates.
outputFormat
Output a single integer denoting the number of distinct ways to distribute the m apples into n plates.
sample
7 2
4