If there are $n$ horses, the number of ways would be the sum of $k! \cdot S(n,k)$ for $1 \le k \le n$ where $S(n,k)$ is the Sterling number of the second kind, see here. For $5$ horses this gives $541$ ways.
Note that $S(n,k)$ counts the number of partitions of the $n$ horses into $k$ unlabeled sets, so must be multiplied by $k!$ because we want to consider which horses are in which place in the race.