#P14611. [NWRRC 2025] Lucky Number Theory

[NWRRC 2025] Lucky Number Theory

题目描述

Lucy is a frequent arcade visitor. All machines at the arcade give out tickets to exchange for prizes! Lucy's favorite machine works as follows.

The machine only has two buttons: "Roll" and "Withdraw". Whenever Lucy presses "Roll", the machine increases the counter on the screen by a randomly generated real\textbf{real} number between 00 and dd. At any moment, she can press "Withdraw" to get the number of tickets equal to the counter, which gets reset. In case it's not an integer, the machine generously rounds the counter up before handing out the tickets.

More formally, the machine stores a real number SS, initially equal to 0. On each "Roll" press, the machine generates Δ\Delta --- a random real\textbf{real} number picked uniformly from the interval (0,d)(0, d). Then, SS increases by the value of Δ\Delta. When the "Withdraw" button is pressed, the machine rounds SS up, giving the player S\lceil S \rceil tickets, and then resets SS back to zero. Lucy can see the value of SS on the screen at any moment with as much precision as she wants, and she can use it to decide whether to roll or withdraw.

Lucy has enough arcade tokens to press "Roll" nn times, and "Withdraw" kk times. Find a strategy that maximizes the expected number of tickets Lucy can get, and print this maximum expected number.

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1t20001 \le t \le 2000). The description of the test cases follows.

The only line of each test case contains three integers nn, kk, and dd, denoting the number of rolls, the number of withdrawals, and the upper bound on roll values (1kn20001 \le k \le n \le 2000; 1d20001 \le d \le 2000).

输出格式

For each test case, print the maximum expected number of tickets Lucy can get, as a floating point number. Your answer will be considered correct if its absolute or relative error doesn't exceed 10610^{-6}.

3
3 2 1
5 5 3
7 1 10
2.6250000000
10.0000000000
35.5000000000

提示

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

Lucy starts with a roll. Depending on the number SS, there are two possibilities:

  • The number is less than 12\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+32=2.51 + \frac 32 = 2.5 (11 ticket for the first withdrawal, and 32\frac 32 tickets on average after two rolls).
  • The number is at least 12\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~14\frac 14 (the probability that the sum of the first two rolls is at most 1, given that the first roll was over 12\frac 12), and two tickets with probability 34\frac 34. The expected number of tickets is 1+234+114=2.751 + 2 \cdot \frac 34 + 1 \cdot \frac 14 = 2.75.

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

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

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