In the first test case, with $n = 3$ rolls, $k = 2$ withdrawals, and $d = 1$, the optimal strategy is as follows:

Lucy starts with a roll. Depending on the number $S$, there are two possibilities:
\begin{shortitems}
\item The number is less than $\frac 12$. In this case, Lucy should withdraw, then roll two more times, and withdraw at the end. The expected number of tickets in this case is $1 + \frac 32 = 2.5$ ($1$ ticket for the first withdrawal, and $\frac 32$ tickets on average after two rolls).
\item The number is at least $\frac 12$. In this case, it's optimal to roll again, withdraw, then roll for the last time, and withdraw at the end. For the first withdrawal, she will get only one ticket with probability~$\frac 14$ (the probability that the sum of the first two rolls is at most 1, given that the first roll was over~$\frac 12$), and two tickets with probability $\frac 34$. The expected number of tickets is $1 + 2 \cdot \frac 34 + 1 \cdot \frac 14 = 2.75$. 
\end{shortitems}

Each case happens with probability $\frac 12$, so the total expected value for this strategy is $\frac 12 (2.5 + 2.75) = 2.625$.

In the second test case, Lucy can withdraw after every roll, each time getting $2$ tickets on average.

In the third test case, Lucy can only withdraw once, and she should do it after all $7$ rolls.