# In how many ways can $7$ people take elevator to $5$th floor such that at the last floor all remaining people exit (at least one remains)?

$7$ people enter the elevator at floor $0$. The elevator finally stops at floor $5$ (elevator direction is only up). No people entered the elevator on floors $1,..,5$. It is possible that some people left the elevator on floors $1,..,4$. On the $5$th floor all the remaining people (at least one remained) exited the elevator. How many ways are possible for people to exist the elevator if people are considered to be different and not different?

If the people are not considered to be different then I think the question is identical to placing $7$ objects into $5$ bins such that the last bin contains at least $1$. That it: $${5-1+7-1\choose 7-1}=210$$ If the people are considered to be different then this is equivalent to permutation with repetitions of $7$ people around $5$ floors. But because in the last floor there must remain at least one person we can count the total permutations $-$ the permutations if there're no one at the last floor: $$5^7-5^6=62500$$

Not sure if I got this one right because the number is quite big.

• I think the second case should be $5^7-4^7=61741$. – gandalf61 Jun 27 '18 at 13:44

If the persons are not distinguishable then it comes to finding the number of sums $n_1+n_2+n_3+n_4+n_5=7$ where $n_1,n_2,n_3,n_4$ are nonnegative integers and $n_5$ is positive integers.
This comes to the same as the numbers of sums $m_1+m_2+m_3+m_4+m_5=6$ where all $m_i$ are nonnegative integers.
With stars and bars we find $\binom{6+4}4=210$ possibilities, and this matches your answer.
How many functions $f:\{1,2,3,4,5,6,7\}\to\{1,2,3,4,5\}$ exist satisfying $5\in\mathsf{im}f$?
The answer is: $$5^7-4^7$$i.e. the number of all functions $f:\{1,2,3,4,5,6,7\}\to\{1,2,3,4,5\}$ minus the number of such functions that do not satisfy $5\in\mathsf{im}f$.