Suppose there are $n$ goats and the building has $n$ floors. Let $a_i$ be the floor preference of goat $i$, with $i=1,\dots,n$. We will say a vector of floor preferences $v=(a_1,a_2,\dots,a_n)$ is “crowded” if it leads to exactly one goat on each floor.
Let $f(n)$ be the number of crowded floor preferences. Since there are $n^n$ total possible preference vectors (each of the $n$ goats can prefer $n$ different floors), the probability that each goat finds a floor is $f(n)/n^n.$ Therefore, solving the problem amounts to finding $f(n)$.
The following elegant counting argument is due to Pollak (1974). We start by considering a modified version of the problem:
- Add one extra floor (the roof). The goats are allowed to pick this $(n+1)^\text{st}$ floor as their preferred floor.
- Just like the other floors, the roof can accommodate at most one goat.
- If a goat ends up on the roof and there is no space for it, the goat “wraps around”; it takes the elevator back down to the first floor and continues its search for an open floor.
In our modified version of the problem, each goat will eventually occupy a floor (possibly the roof), and there will be exactly one empty floor. If the empty floor is the roof, then no goat had the roof as its preferred floor, no goat ever visited the roof, and no goat ever had to take the elevator back down. Therefore, the vector of floor preferences was crowded according to our original definition. Conversely, if one of the other floors ends up empty, then a goat ended up on the roof, which means the original vector of floor preferences was either invalid (one of the goats picked the roof), or the preferences were valid but a goat nonetheless overflowed onto the roof.
So not only is $f(n)$ equal to the number of crowded preference vectors in the original problem, it is also equal to the number of preference vectors in the modified problem that lead to the roof being empty.
The final piece to this argument is to realize that there must be an equal number of preference vectors that lead to the $k^\text{th}$ floor being empty, for $k=1,\dots,n+1$. This follows because of the symmetry in the modified version of the problem. Specifically, if a particular preference vector $(a_1,\dots,a_n)$ leads to floor $k$ being empty, then $(a_1+j,\dots,a_n+j)$ leads to floor $k+j$ being empty (where we wrap all numbers around so they are in the range between $1$ and $n+1$).
Since there are $(n+1)^n$ total possible preference vectors for the modified problem (each of the $n$ goats can prefer $n+1$ different floors), and there are $n+1$ possible empty floors, we obtain
\[
f(n) = \frac{(n+1)^n}{n+1} = (n+1)^{n-1}
\]Converting this number into a probability as explained at the beginning of the solution, we find that the probability that $n$ goats have a crowded set of preferences is
$\displaystyle
p(n) = \frac{(n+1)^{n-1}}{n^n} = \frac{1}{n+1}\left(1+\frac{1}{n}\right)^n
$
For the case $n=10$, we can calcluate:
\[
p(10) = \frac{11^9}{10^{10}} = \frac{2{,}357{,}947{,}691}{10{,}000{,}000{,}000} \approx 23.58\%
\]
Since $\lim_{n\to\infty} \left(1+\frac{1}{n}\right)^n = e$, it follows that in the asymptotic limit of large $n$, we have $p(n) \sim \frac{e}{n+1}$. Here is a plot comparing the true probability to this asymptotic approximation.

About this problem’s history
This sort of counting problem, where you start with a preference and move to the next available open slot, is also known as a parking problem, because its original formulation was about cars trying to park on a one-way street and taking the next available open spot. There are many other equivalent counting problems, which you can find more about in the entry A000272 in the Online Encyclopedia of Integer Sequences. For a wonderful explanation of the parking problem and other related counting problems, take a look at Richard Stanley’s slides on the topic. The solution in my post above is based on the argument in Richard’s slides, which is due to Pollak (1974).