The Wheel of Fortune

“Welcome to the Wheel of Fortune! (aplause) Here, come here: do you see
this big wheel? You can spin it as many times as you want, unless...
well, you’ll see. There are n landing wedges. Some of them have a value
from $1 to 10, which is the money you will get if you land on them. (Not
much money, true. It’s the crisis). Great, right? And what about that 0,
you ask? Well, every Wheel of Fortune has at least one of these. If you
land on it, then, you lose everything. And you can’t spin the wheel no
more.”

Are you ready for the problem? Given the n wedges in the Wheel of
Fortune, please find the optimal strategy for deciding when to stop and
when to keep spinning, and compute how much money you expect to obtain
(on average) if you follow that optimal strategy.

For instance, for a wheel with n = 3 and wedges 0, 0 and $9, the optimal
strategy is to spin it once and, if you survive that spin, stop and cash
the $9. The expected gain is $3.

Input

Input begins with the number of cases t, followed by t lines, each of
them with n followed by the n values of the wedges, at least one of
which will be a 0. Assume 1 ≤ n ≤ 10⁴.

Output

Print t lines, each with the amount of dollars you can expect to make
for the corresponding Wheel of Fortune, rounded to the closest cent,
that is, with two digits after the decimal point. The input cases have
no precision issues.

Problem information

Author: Omer Gimenez

Generation: 2026-01-25T11:33:28.214Z

© Jutge.org, 2006–2026.
https://jutge.org
