Calculating the number of combinations we can put people in a queue with some restrictions Suppose we have $n$ number of persons, all with different heights. We need to stack them such that only $x$ are seen from the front and $y$ are seen from the back. Smaller people are hidden behind bigger persons. 
Examples:
x=y=2    n=3 2: 132, 231 
x=y=2    n=4 6: 1423, 2143, 2413, 3142, 3241, 3412
x=1 y=3  n=5 11: 51243, 51342, 51423, 52143, 52341, 52413, 53142, 53241, 53412, 

When we take the $x$ largest persons to the front and the next $y-1$ largest persons to the back, we can insert the rest between them. This gives us a solution, but we're interested in the number of possible combinations we can put them.
54123, 54213

I simulated the results up to n=8 and found some interesting results on http://oeis.org/, but I'm not sure how I can put this together. I pasted it to pastebin, since it's quite long. 
Tl;dr relevant functions:


*

*Triangle related to the asymptotic expansion of E(x,m=3,n)

*Array of numbers f(n,k) from n-th differences of sequence {1/x^2}; n-th difference is n!*P(x)/(D^2) where P(x) is a degree-n polynomial: P(n) = Sum_k { f(n,k)*x^k } and D = x(x+1) ...(x+n-1)(x+n)
I know some of these words, but this is essentially magic to me right now. Can anyone help me make sense of it and put together a coherent formula?
 A: There are essentially no restrictions on who can go in front of the tallest person as long as there are at least $x - 1$ people in that group, or on who can go behind as long as you have at least $y - 1$ people there. For example, you could put the $x - 1$ shortest people in front of the tallest one, as long as you put everyone else behind.
Within the group in front of the tallest person, you must put at least $x - 2$ people in front of the tallest person in that group, but you can choose any $x - 2$ from that group for that purpose. After that you just have to find how many different ways you can hide the remaining people.
There are similar considerations for the group behind the tallest person.
The number of arrangements of these groups of people is the product of the number of
arrangements of the group in front times the number of arrangements of the group behind.
However, the number of ways you can choose the $x - 2$ people to be visible in the first group depends on how many are in the first group, and then the number of ways you can hide the others depends on who you chose to make visible.
Similarly for the other group.
I don't see an obvious easy solution in closed form.
You could use a computer program to do the counting but unless it's a brute-force method
you'd have to be careful that you use formulas that neither overcount nor undercount.
("Brute force" means that for each of the $n!$ possible permutations of the numbers
$1$ through $n$ you construct that permutation and check whether it
satisfies the criteria.)
Addendum: Some thoughts about how to count the arrangements,
not necessarily leading to "closed form" but perhaps simplifying the calculation.
I'll write $f(n,x,y)$ to mean the number of ways to arrange the $n$ people so that $x$
are visible from the front and $y$ from the back.
Also let $g(n,x)$ be the number of ways to arrange $n$ people so that $x$ are visible
from the front. Note that $g(m,k)$ defined this way is also the number of ways to 
arrange $m$ people so that $k$ are visible from the back.
Use the numbers $1,2,3,\ldots,n,$ in that sequence, to label the places in a
line of $n$ people from front to back.
To make one of the $f(n,x,y)$ arrangements,
where $x > 1,$ $y > 1,$ and $n \geq x + y - 1,$ we can put the tallest person in
position $x$ or $n-y+1$ or any position between those.
If we put the tallest person in position $j$,
then there are $\binom{n-1}{j-1}$ ways to choose who will be in front of position $j$
and who will be behind.
For each of those choices, there are $g(j-1,x-1)$ ways to arrange the people in front
and for each of these there are $g(n-j,y-1)$ ways to arrange the people behind, so
$$ f(n,x,y) = \sum_{j=x}^{j=n-y+1} \binom{n-1}{j-1} g(j-1,x-1) \  g(n-j,y-1). $$
If $x=1$ and $y > 1,$ then we must put the tallest person in position $1$ and
arrange the others so that $y - 1$ are visible from behind, so
$f(n,x,y) = g(n,y-1).$
For similar reasons, if $x > 1$ and $y = 1$ then $f(n,x,y) = g(n,x-1).$
If $x=y=1$ there is one arrangement for $n=1$ and no arrangements at all for $n>1.$
For $g(m,k),$ the tallest person in that set of $m$ people can be placed at any
of the positions $k,k+1,\ldots,m.$
If we put that person at position $i,$ 
then there are $\binom{m-1}{i-1}$ ways to choose who goes ahead of position $i,$
and for each of those choices there are $g(i-1,k-1)$ ways to arrange those people
and $(m-i)!$ ways to arrange the others, so for $m > k > 1,$
$$\begin{eqnarray}
 g(m,k) &=& \sum_{i=k}^{i=m} \binom{m-1}{i-1} ((m-i)!) \  g(i-1,k-1) \\
        &=& (m-1)! \sum_{i=k}^{i=m} \frac{ g(i-1,k-1)}{(i-1)!}.
\end{eqnarray}$$
To be able to see all $m$ people from the front they must be lined up by
increasing size, so $g(m,m) = 1,$
whereas to see only one person we put the tallest person in front and 
arrange the rest in any order we want, so $g(m,1) = (m-1)!$
for any positive integer $m.$
I wouldn't call this a closed form, but it seems reasonably tractable to compute,
something like $O(n^2)$ time to compute $f(n,x,y)$ 
if you assume constant-time random access to an $n \times n$ array of values.
A: It is mentioned here, as a famous theorem of Rényi, that "the number of permutations of $[k]$ with $r$ strongly outstanding elements is equal to the number of permutations with $r$ cycles" and that that equals $\left[k  \atop r\right]$, the unsigned Stirling number of the first kind.
If I'm not mistaken, that is equivalent to $g(k,r)$ in David's answer.
