2485. Millionaire

单点时限: 2.0 sec

内存限制: 256 MB

You have been invited to the popular TV show “Would you like to be a millionaire?”. Of course you would!

The rules of the show are simple:

  • Before the game starts, the host spins a wheel of fortune to determine P, the probability of winning each bet.
  • You start out with some money: X dollars.
  • There are M rounds of betting. In each round, you can bet any part of your current money, including none of it or all of it. The amount is not limited to whole dollars or whole cents.

If you win the bet, your total amount of money increases by the amount you bet. Otherwise, your amount of money decreases by the amount you bet.

  • After all the rounds of betting are done, you get to keep your winnings (this time the amount is rounded down to whole dollars) only if you have accumulated $1000000 or more. Otherwise you get nothing.
  • Given M, P and X, determine your probability of winning at least $1000000 if you play optimally (i.e. you play so that you maximize your chances of becoming a millionaire).


    The first line of input gives the number of cases, N(1 ≤ N ≤ 100).

    Each of the following N lines has the format “M P X”, where:

    • M(1 ≤ M ≤ 15) is an integer, the number of rounds of betting.
    • P(0 ≤ P ≤ 1.0, there will be at most 6 digits after the decimal point.) is a real number, the probability of winning each round.
    • X(1 ≤ X ≤ 1000000) is an integer, the starting number of dollars.


    For each test case, output one line containing “Case #X: Y”, where:

    • X is the test case number, beginning at 1.
    • Y is the probability of becoming a millionaire, between 0 and 1.

    Answers with a relative or absolute error of at most 10-6 will be considered correct.


    1 0.5 500000
    3 0.75 600000
    Case #1: 0.500000
    Case #2: 0.843750
    In the first case, the only way to reach $1000000 is to bet everything in the single round.
    In the second case, you can play so that you can still reach $1000000 even if you lose a bet. Here's one way to do it: You have $600000 on the first round. Bet $150000. If you lose the first round, you have $450000 left. Bet $100000.
    If you lose the first round and win the second round, you have $550000 left. Bet $450000. If you win the first round, you have $750000 left. Bet $250000. If you win the first round and lose the second round, you have $500000 left. Bet $500000.

    0 人解决,4 人已尝试。

    0 份提交通过,共有 22 份提交。

    9.9 EMB 奖励。

    创建: 15 年,3 月前.

    修改: 6 年,10 月前.

    最后提交: 2 年,2 月前.

    来源: GCJ 2008