If \$R\$ runners were to run a race, in how many orders could they finish such that exactly \$T\$ runners tie?
Challenge
Given a positive integer \$R\$ and a non-negative integer \$0\leq T\leq {R}\$ produce the number of possible finishing orders of a race with \$R\$ runners of which \$T\$ tied.
Note, however, that runners that tie do not necessarily all tie with each other.
You may accept the number of runners that did not tie, \$R-T\$, in place of either \$R\$ or \$T\$ if you would prefer, just say so in your answer. You may also accept just \$R\$ and output a list of results for \$0\leq T \leq R\$.
This is code-golf, so try to make the shortest code in bytes in your language of choice.
Examples
1. \$f(R=5, T=0)=120\$
No runners tied and the five runners could have finished in any order, thus \$f(R=5, T=0)=R!=5!=120\$
2. \$f(R=5, T=1)=0\$
There are zero ways for exactly one runner to have tied since ties involve at least two runners.
3. \$f(R=4, T=2)=36\$
- The first two tied -
** * *
- \$\binom{4}{2}\binom{2}{1}\binom{1}{1}=6\times 2\times 1=12\$ ways:AB C D
AB D C
AC B D
AC D B
AD B C
AD C B
BC A D
BC D A
BD A C
BD C A
CD A B
CD B A
- The middle two tied -
* ** *
- \$\binom{4}{1}\binom{3}{2}\binom{1}{1}=4\times 3\times 1=12\$ ways:A BC D
A BD C
A CD B
B AC D
B AD C
B CD A
C AB D
C AD B
C BD A
D AB C
D AC B
D BC A
- The last two tied -
* * **
- \$\binom{4}{1}\binom{3}{1}\binom{2}{2}=4\times 3\times 1=12\$ ways:A B CD
A C BD
A D BC
B A CD
B C AD
B D AC
C A BD
C B AD
C D AB
D A BC
D B AC
D C AB
4. \$f(R=5, T=5)=21\$
- All five runners tied -
*****
- \$\binom{5}{5}=1\$ way - The first two and the last three tied -
** ***
- \$\binom{5}{2}\binom{3}{3}=10\times 1=10\$ ways:AB CDE
AC BDE
AD BCE
AE BCD
BC ADE
BD ACE
BE ACD
CD ABE
CE ABD
DE ABC
- The first three and the last two tied -
*** **
- \$\binom{5}{3}\binom{2}{2}=10\times1=10\$ ways:ABC DE
ABD CE
ABE CD
ACD BE
ACE BD
ADE BC
BCD AE
BCE AD
BDE AC
CDE AB
Test cases
R,T => f(R,T)
1,0 => 1
1,1 => 0
2,0 => 2
2,1 => 0
2,2 => 1
3,0 => 6
3,1 => 0
3,2 => 6
3,3 => 1
4,0 => 24
4,1 => 0
4,2 => 36
4,3 => 8
4,4 => 7
5,0 => 120
5,1 => 0
5,2 => 240
5,3 => 60
5,4 => 100
5,5 => 21
7,5 => 5166
As a table, with x
if the input does not need to be handled (all of them would be zero):
T R: 1 2 3 4 5 6 7
0 1 2 6 24 120 720 5040
1 0 0 0 0 0 0 0
2 x 1 6 36 240 1800 15120
3 x x 1 8 60 480 4200
4 x x x 7 100 1170 13440
5 x x x x 21 372 5166
6 x x x x x 141 3584
7 x x x x x x 743
Isomorphic problem
This is the same as \$a(n=R,k=R-T)\$ which is given in A187784 at the Online Encyclopedia of Integer Sequences as the number of ordered set partitions of \$\{1,2,\dots,n\}\$ with exactly \$k\$ singletons.