Statistics

Problem Statement for "SureThing"

Problem Statement

Various numbers of different-colored (but otherwise identical) marbles are placed in a bag. Marbles are randomly removed from the bag one at a time. You are given the opportunity to guess the color of each marble immediately before it is removed, and with each guess you place a wager. If the color of the marble matches your guess you win the amount of your wager, otherwise you lose that amount.

Each wager can be anywhere from 0 to the total amount of money you have at the time of your wager, inclusive. Your goal is to carefully choose your wagers in order to guarantee yourself the highest possible winnings in the end. Given the total number of marbles of each color initially in the bag and $1.00, determine the greatest amount of money you can guarantee yourself to end up with.

For example, if the bag starts with 1 blue, 1 red, and 1 yellow marble, your best strategy is to wager zero on the first two marbles and then wager everything on the third marble, guaranteeing yourself $2.00 at the end. If you wager anything on either of the first two marbles, there is a chance that you will guess wrong and lose money. Even after doubling your money on the last marble you could end up with less than $2.00. So in this case, the answer is 2.

You can always end up with $2.00 by waiting until there is only one marble left. But often you can do better than that. If the bag begins with 1 blue and 2 red marbles, your best strategy is to bet 1/3 of your money on red. If you are correct (the first marble is red), you will end up with 4/3, bet nothing on the second marble, and then double your money betting on the last marble to 8/3. If you are incorrect (and the first marble is blue) you will have 2/3 left, but you will be able to double your money twice (because you know the last two marbles are both red), thus ending up with 8/3. Notice that you don't care if your first guess is right or wrong -- either outcome leads to ending up with 8/3.

Definition

Class:
SureThing
Method:
maximum
Parameters:
int[]
Returns:
double
Method signature:
double maximum(int[] marbles)
(be sure your method is public)

Notes

  • Don't worry about betting an integral number of coins. Assume your money is infinitely divisible. Wagers such as 1/3 and sqrt(2) are perfectly legal.
  • Your return must have an absolute or relative error less than 1e-9.

Constraints

  • marbles will contain between 1 and 6 elements, inclusive.
  • Each element of marbles will be between 1 and 100, inclusive.

Examples

  1. { 1, 1, 1 }

    Returns: 2.0

    This is the first example in the problem statement.

  2. {1, 2}

    Returns: 2.666666666666667

    This is the second example in the problem statement.

  3. {10}

    Returns: 1024.0

    With 10 marbles all the same color, you can "guess" correctly 10 times, doubling your money each time.

  4. {26, 26}

    Returns: 9.081329549427792

    This is the version of the game that you can play with a deck of cards, guessing if each one will be black or red.

  5. {1, 2, 23}

    Returns: 25565.281523809546

  6. {1, 1, 23}

    Returns: 111476.51827242554

  7. {1, 2, 22}

    Returns: 14438.223752151483

  8. {23, 23, 23 }

    Returns: 2.6172956876844395

  9. {1, 2, 3, 4, 5, 100 }

    Returns: 1.6979400579163614E16

  10. { 100, 100, 100 }

    Returns: 2.618033988542907

  11. { 25, 50, 75, 100 }

    Returns: 2.192341741646549

  12. { 100, 100, 100, 100, 100, 100 }

    Returns: 2.0352521616197237

  13. { 100 }

    Returns: 1.2676506002282294E30

  14. {1,1,1,1,1,100}

    Returns: 4.192823700616432E23

  15. {1,1,1,1,2,100}

    Returns: 4.741988520934138E22

  16. {100,1,1,1,1,1}

    Returns: 4.192823700616432E23

  17. {1,1,1,1,1,1}

    Returns: 2.0

  18. {1,1,1,1,2,1}

    Returns: 2.0317460317460316

  19. { 1, 100 }

    Returns: 2.51019920837279E28

  20. { 100, 100 }

    Returns: 17.746707942830696

  21. { 100, 1, 100 }

    Returns: 11.909750845354827

  22. { 82, 35, 2, 58, 91, 14 }

    Returns: 2.0358997127416867

  23. {100,10,10,10,10,10}

    Returns: 54642.99957859558


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: