Up the Ante

Time limit1sMemory limit128 MB

Summary
Given per-round win probabilities, find the chance a capped martingale strategy shows a positive balance at some round from k through m.
Level

Medium6 of 10

Topics
Probability, Dynamic programming, Simulation, Implementation
Solved
No attempts yet

Problem

Stan likes to play Crown & Anchor, a gambling game in which one bets on one of six symbols: Crown, Anchor, Club, Diamond, Heart, or Spade.

A wheel is spun and stops in a position marked by three symbols (not necessarily distinct). If the symbol Stan bet on appears nn times among the three, he receives his bet back plus nn times his bet — that is, his net gain is nn times his bet. If his symbol does not appear at all, he loses his bet.

Stan has made a side bet with Ollie: that he can make money playing Crown & Anchor. Ollie realizes Stan might get lucky and win the first few rounds, so he insists that, to win the bet, Stan must be ahead after at least kk rounds. Also, so the matter is settled quickly, Stan must show a profit within at most mm rounds.

Stan's plan is the Monte Carlo (martingale) betting strategy. He first places the minimum bet. If he wins, he pockets the profit and again places the minimum bet. If he loses, he doubles his bet, so that winning the next round recoups his previous losses and still yields a profit. This doubling continues until he wins; whenever he wins, he pockets the profit and starts over at the minimum bet.

The house counters with a house limit ll: the maximum bet allowed in any single round. Stan therefore adjusts his strategy: if doubling his bet would exceed the house limit, he starts over at the minimum bet instead, hoping to recover the loss later.

The minimum bet is 11. Following this strategy, Stan wins the side bet if his net winnings are strictly positive at any checkpoint from after round kk through after round mm. Find the probability that Stan wins the side bet.

Input

The first line contains nn, the number of test cases. Each test case is a single line with three integers kk, mm, and ll: the minimum number of rounds after which Stan must be ahead, the maximum number of rounds, and the house limit.

  • 0<k<m≤300 < k < m \le 30
  • 2≤l≤10002 \le l \le 1000
  • The minimum bet is 11.

Output

For each test case, print the probability that Stan wins the side bet, rounded to 44 decimal places, on its own line.

Hint

The wheel has 2828 stopping positions. There are 1414 distinct symbol combinations, and each appears twice on the wheel. The 1414 combinations consist of:

  • 66 combinations of three identical symbols (one per symbol),
  • 66 combinations with exactly two identical symbols,
  • 22 combinations of three distinct symbols.

The layout is symmetric, so every symbol has the same distribution of appearance counts. For any chosen symbol, counting the stopping positions gives:

  • appears 33 times: 22 positions
  • appears 22 times: 22 positions
  • appears 11 time: 44 positions
  • does not appear: 2020 positions

Hence, in a single round, the number of times the chosen symbol appears has probabilities

P(0)=2028,P(1)=428,P(2)=228,P(3)=228P(0) = \frac{20}{28},\quad P(1) = \frac{4}{28},\quad P(2) = \frac{2}{28},\quad P(3) = \frac{2}{28}

Examples2

  1. Example 1

    Input
    1
    3 4 10
    
    Expected output
    0.5835
    
  2. Example 2

    Input
    2
    1 2 2
    5 10 1000
    
    Expected output
    0.4898
    0.9140