Statistics

Problem Statement for "Flush"

Problem Statement

You are playing a card game in which large flushes, or sets of cards of the same suit, are beneficial. Your next move is to draw number cards: the larger the flush you get, the better. You wish to know the expected size of the largest flush in the cards you draw. The deck will consist of some number of cards of four suits, given as suits. The ith element of suits is the number of cards of that suit in the deck. Return a double, the expected size of the largest flush your hand will make.

The expected size of the largest flush is calculated as follows: For each possible hand, multiply the size of the largest flush in that hand by the probability of getting that hand. Then add all of these values together to get the expected size of the largest flush. For example, if half of the possible hands give you a flush of size 3, and the rest give you one of size 2, the expected value is (0.5 * 3) + (0.5 * 2) = 2.5. Also, recall that there are n Choose k = n!/k!/(n-k)! ways to select k cards of one suit out of a total of n cards in that suit, where ! denotes the factorial operation. Thus, if suits = {3,3,3,3}, then there are (3 Choose 3) * (3 Choose 2) * (3 Choose 1) * (3 Choose 0) = 1 * 3 * 3 * 1 = 9 ways to get 3 cards of the first suit, 2 of the second, 1 of the third, and none of the fourth.

Definition

Class:
Flush
Method:
size
Parameters:
int[], int
Returns:
double
Method signature:
double size(int[] suits, int number)
(be sure your method is public)

Notes

  • Look out for overflow! A 32-bit datatype may not be large enough.
  • Your return value must have an absolute or relative error less than 1e-9.

Constraints

  • suits will contain exactly four elements.
  • Each element of suits is between 0 and 13, inclusive.
  • number is between 0 and the sum of the elements of suits, inclusive.

Examples

  1. {2,2,2,2}

    2

    Returns: 1.1428571428571428

    Draw the first card; you have a 1 out of 7 chance to draw the matching suit for your second card. The expected size is thus (1/7 * 2) + (6/7 * 1) = 8/7 = 1.1428571428571428.

  2. {1,4,7,10}

    22

    Returns: 10.0

    You are drawing all of the cards, so your largest flush will be of size 10.

  3. {13, 13, 13, 13}

    49

    Returns: 13.0

    If you get 12 cards of each suit, you must have drawn 48 cards, so drawing 49, 50, 51, or 52 cards must give you a flush of size 13.

  4. {13, 13, 13, 13}

    26

    Returns: 8.351195960938014

  5. {13,13,13,13}

    0

    Returns: 0.0

  6. {8,2,6,13}

    5

    Returns: 2.6879457707043914

  7. {2,1,7,8}

    7

    Returns: 3.692684766214178

  8. {11,10,10,13}

    44

    Returns: 13.0

  9. {13,10,9,2}

    23

    Returns: 9.064637860149622

  10. {0,4,0,11}

    15

    Returns: 11.0

  11. {11,10,0,5}

    19

    Returns: 8.539715719063546

  12. {3,3,4,12}

    21

    Returns: 11.454545454545455

  13. {8,3,6,5}

    13

    Returns: 5.069675525712677

  14. {13,1,1,6}

    13

    Returns: 8.053943682736252

  15. {12,6,2,7}

    16

    Returns: 7.193079864502667

  16. {4,7,9,11}

    23

    Returns: 8.41418898491201

  17. {0,7,0,0}

    5

    Returns: 5.0

  18. {5,2,2,12}

    15

    Returns: 8.571428571428571

  19. {3,13,5,8}

    24

    Returns: 10.758620689655173

  20. {8,9,4,2}

    9

    Returns: 4.169051261028647

  21. {12,4,12,3}

    1

    Returns: 1.0

  22. {8,13,4,6}

    27

    Returns: 11.32258064516129

  23. {13,11,6,6}

    11

    Returns: 4.674274494078361

  24. {11,4,13,9}

    5

    Returns: 2.5291433526727642

  25. {6,12,9,12}

    29

    Returns: 9.793681675360492

  26. {6,9,3,3}

    2

    Returns: 1.2714285714285714

  27. {9,3,5,3}

    2

    Returns: 1.2736842105263158

  28. {6,0,6,2}

    2

    Returns: 1.3406593406593406

  29. {7,13,3,7}

    7

    Returns: 3.4360207289517635

  30. {2,3,11,9}

    0

    Returns: 0.0

  31. {13, 13, 13, 13 }

    26

    Returns: 8.351195960938014

  32. {13, 13, 13, 13 }

    49

    Returns: 13.0

  33. {4, 4, 4, 4 }

    4

    Returns: 1.9692307692307693

  34. {13, 13, 13, 13 }

    47

    Returns: 12.73625450180072

  35. {1, 2, 0, 0 }

    3

    Returns: 2.0

  36. {11, 7, 4, 1 }

    11

    Returns: 5.46901953881359


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: