TITLE: Distinct balls into distinct boxes
QUESTION [5 upvotes]: We have $n$ distinct balls ($n>7$) and want to randomly (and independently) distribute them into $N$ distinct boxes ($N>n$) which are placed one next to the other.
a) What is the probability that all balls are placed in consecutive boxes?
b) What is the probability that all balls are placed in consecutive boxes and balls with number $1$, $4$ and $7$ are also placed in consecutive boxes?

I am not sure but I will try:
a) There is a block of n balls which must be placed in one of the $N-n+1$ gaps formed if we arrange the boxes and fill $n$ consecutive of them. So there are $N-n+1$ places place this block. The $n$ balls in the block can be arranged in $n!$ ways. Also the N boxes can be arranged in $N!$ ways. So all in all we have $n!N!(N-n+1)$.
b) Again we have $N!$ ways to arrange the boxes but the balls can be arranged in $(n-3)!$ ways, right?
I don't know what is the total number of ways to place all balls in the boxes - plus that I see no restriction regarding the number of balls per box.
Any help?

REPLY [2 votes]: In this answer (only on a)) a subset $S\subseteq\left\{ 1,\dots,N\right\} $ gets
the label consecutive if no $k\in\left\{ 1,\dots,N\right\} $
exists with $k\notin S$, $\left\{ 1,\dots,k-1\right\} \cap S\neq\varnothing$
and $\left\{ k+1,\dots,N\right\} \cap S\neq\varnothing$.
Let $\hat{S}$ denote the random subset of $\left\{ 1,\dots,N\right\} $
determined by: $$s\in\hat{S}\iff\text{at least one ball is placed in box }s$$

If every box can contain at most one ball then $\hat{S}$ will be
a subset of cardinality $n$ and there are $\binom{N}{n}$ equiprobable
candidates of which $N-n+1$ are consecutive. 
This leads to: $$P\left(\hat{S}\text{ is consecutive}\right)=\left(N-n+1\right)\binom{N}{n}^{-1}$$

If every box can contain more than one ball then we will use the following
nice formula: $$P\left(\hat{S}=S\right)=\sum_{T\subseteq S}P\left(\hat{S}\subseteq T\right)\left(-1\right)^{\left|S\right|-\left|T\right|}\tag1$$
This formula arises if we first write: $$P\left(\hat{S}=S\right)=P\left(\hat{S}\subseteq S\right)-P\left(\bigcup_{s\in S}\left\{ \hat{S}\subseteq S-\left\{ s\right\} \right\} \right)$$
and then apply the principle of inclusion/exclusion on the second term on RHS. 
In our situation $P\left(\hat{S}\subseteq T\right)=N^{-n}\left|T\right|^{n}$
and $\binom{\left|S\right|}{i}$ subsets $T\subseteq S$ have cardinality
$i$.
Based on that we can further expand $\left(1\right)$ with:
$$P\left(\hat{S}=S\right)=\cdots=N^{-n}\sum_{T\subseteq S}\left|T\right|^{n}\left(-1\right)^{\left|S\right|-\left|T\right|}=N^{-n}\sum_{i=1}^{\left|S\right|}\binom{\left|S\right|}{i}i^{n}\left(-1\right)^{\left|S\right|-i}$$
If we denote $\mathcal{C}_{k}$ as the collection of consecutive
subsets of $\left\{ 1,\dots,N\right\} $ that have exactly $k$ elements
then $\left|\mathcal{C}_{k}\right|=N-k+1$ so that by symmetry:
$$P\left(\hat{S}\text{ is consecutive}\right)=\sum_{k=1}^{n}P\left(\hat{S}\in\mathcal{C}_{k}\right)=\sum_{k=1}^{n}\left(N-k+1\right)P\left(\hat{S}=\left\{ 1,\dots,k\right\} \right)=$$$$N^{-n}\sum_{k=1}^{n}\left(N-k+1\right)\sum_{i=1}^{k}\binom{k}{i}i^{n}\left(-1\right)^{k-i}$$