# Assigning $m$ balls to $n$ buckets - recursive algorithm

I came across the following problem and the answer to that problem:

Given $$m$$ balls and $$n$$ bins, find out how many ways to assign the balls to the bins. Notice the bins have no order: for example, $$(1,2,3)$$ and $$(3,2,1)$$ are considered the same.

As an example, if $$m = 3$$ and $$n = 2$$, you should return 2, since there are two possibilities: $$(1,2)$$ and $$(3,0)$$.

Here is a recurrence which seems to work: $$f(m,n) = \begin{cases} 1 & \text{if } m = 0 \text{ or } n = 1 \\ f(m,m) & \text{if } n > m \\ f(m,n-1) + f(m-n, n) & \text{if } 1 < n \leq m \end{cases}$$

This solution seem to work. However I don't understand how $$f(m,n-1) + f(m-n,n)$$ works. Why is it considering $$m-n$$ balls into $$n$$ bins?

An assignment of balls into $$n$$ bins falls into either one of the following two cases.
• Otherwise. That is, there is at least one bin that has no ball. This case is the same as assigning all balls into $$n-1$$ bins.