Correct solutions were submitted by Paul Lee, Dan Dima, Flam', Burkart Venzke, Nancy Schwarzkopf, Juan Carlos Marivela, Brett Hendricks and Steven Prowse.
The nth person in line wins if their birthday matches one of the previous customers' birthdays, each of which is distinct. There are n-1 previous customers to match, and D!/(D-n+1)! ways to pick a different birthday for each. If each assignment of n birthdays is equally likely to occur, then the probability that the nth person in line wins is thus
.
We want to find the n that maximizes W(n).
Notice that
is positive when n is less than
and negative when n is greater than this.
With either value of D, this means the (n+1)st person is more likely to win than the nth person from n=1 through n=19 and less likely from n=20 onward, so I want to be 20th in line. (Unfortunately, I still only have about a 3.23% chance of winning.)