Statistics

Problem Statement for "TheTicketsDivTwo"

Problem Statement

John has two tickets for the basketball game - one for himself and one for a friend. However, he has n friends who want to go with him. He decides to use the following strategy to choose one of them. First, he tells his friends to form a straight single file line. Then, he repeats the following step until he has made a choice. If there is only one friend in line, John chooses him. Otherwise, he throws a standard six-sided die. If the number 4 is on top, he chooses the friend who is currently first in line. Otherwise, if the number is odd, the first friend in line must move to the end of the line, and if the number is even, the first friend in line must leave the line and go home.

While the initial John's intention is to throw a die until some friend is chosen, in practice he gets tired quickly. If after k throws of a die he still hasn't chosen a friend, he prefers to stop the process and to choose the friend who is currently first in line.

You are given an int m, the 1-based index of a friend in the initial line. The index of the first friend is 1, and the index of the last friend is n. Return the probability that the m-th friend in the initial line is ultimately chosen by John.

Definition

Class:
TheTicketsDivTwo
Method:
find
Parameters:
int, int, int
Returns:
double
Method signature:
double find(int n, int m, int k)
(be sure your method is public)

Notes

  • The returned value must be accurate to within a relative or absolute value of 1E-9.

Constraints

  • n will be between 1 and 10, inclusive.
  • m will be between 1 and n, inclusive.
  • k will be between 1 and 10, inclusive.

Examples

  1. 2

    1

    1

    Returns: 0.16666666666666666

    There is 1/6 probability that John will choose the first friend after the first throw of a die.

  2. 2

    1

    2

    Returns: 0.5833333333333334

    The first friend will go to the game if John chooses him after the first throw, or if he goes to the end of the line after the first throw and Jonh doesn't choose the second friend after the second throw. The overall probability is 1/6 + 1/2 * 5/6.

  3. 7

    7

    4

    Returns: 0.0

    There's no chance for the last friend in the line to be chosen.

  4. 4

    2

    10

    Returns: 0.25264033564814814

  5. 9

    1

    4

    Returns: 0.16666666666666666

  6. 5

    5

    6

    Returns: 0.12152777777777778

  7. 1

    1

    10

    Returns: 1.0

  8. 10

    1

    6

    Returns: 0.16666666666666666

  9. 7

    2

    6

    Returns: 0.1388888888888889

  10. 6

    3

    9

    Returns: 0.1586210776748971

  11. 4

    1

    2

    Returns: 0.16666666666666666

  12. 6

    1

    7

    Returns: 0.20187114197530864

  13. 8

    2

    7

    Returns: 0.1388888888888889

  14. 2

    1

    9

    Returns: 0.443359375

  15. 2

    2

    3

    Returns: 0.625

  16. 9

    9

    9

    Returns: 0.0388883530521262

  17. 8

    6

    9

    Returns: 0.07633887745770462

  18. 7

    1

    4

    Returns: 0.16666666666666666

  19. 3

    2

    9

    Returns: 0.3168402777777778

  20. 9

    7

    6

    Returns: 0.33489797668038407

  21. 6

    1

    9

    Returns: 0.22116126543209877

  22. 3

    2

    10

    Returns: 0.3184678819444444

  23. 5

    1

    10

    Returns: 0.24895109953703703

  24. 7

    1

    8

    Returns: 0.19514639060356653

  25. 6

    1

    9

    Returns: 0.22116126543209877

  26. 1

    1

    9

    Returns: 1.0

  27. 3

    3

    10

    Returns: 0.3439670138888889

  28. 7

    7

    8

    Returns: 0.06210348079561043

  29. 2

    2

    10

    Returns: 0.5550130208333334

  30. 2

    1

    10

    Returns: 0.4449869791666667

  31. 9

    1

    10

    Returns: 0.18611084319272977

  32. 5

    5

    10

    Returns: 0.16149450231481483

  33. 1

    1

    10

    Returns: 1.0

  34. 10

    1

    10

    Returns: 0.2635700164005741

  35. 7

    2

    10

    Returns: 0.17257962534293553

  36. 6

    3

    10

    Returns: 0.1668997556584362

  37. 4

    1

    10

    Returns: 0.28313078703703703

  38. 6

    1

    10

    Returns: 0.23161008230452676

  39. 8

    2

    10

    Returns: 0.16096313085848193

  40. 2

    1

    10

    Returns: 0.4449869791666667

  41. 3

    1

    10

    Returns: 0.3375651041666667

  42. 2

    2

    10

    Returns: 0.5550130208333334

  43. 3

    3

    10

    Returns: 0.3439670138888889

  44. 2

    1

    10

    Returns: 0.4449869791666667

  45. 10

    10

    10

    Returns: 0.03234345429749022

  46. 1

    1

    10

    Returns: 1.0

  47. 4

    1

    10

    Returns: 0.28313078703703703

  48. 10

    3

    10

    Returns: 0.13124527669816594

  49. 10

    7

    10

    Returns: 0.05621324556724076

  50. 9

    8

    7

    Returns: 0.2790816472336534

  51. 10

    4

    10

    Returns: 0.10265243166692069

  52. 6

    5

    4

    Returns: 0.48225308641975306

  53. 5

    4

    3

    Returns: 0.5787037037037037

  54. 3

    3

    4

    Returns: 0.3472222222222222

  55. 10

    6

    10

    Returns: 0.06797188563735203

  56. 10

    8

    9

    Returns: 0.04651360787227557

  57. 10

    5

    10

    Returns: 0.08285624015648022

  58. 5

    2

    3

    Returns: 0.1388888888888889

  59. 9

    2

    9

    Returns: 0.18540249676116446

  60. 4

    2

    8

    Returns: 0.25752314814814814

  61. 2

    2

    1

    Returns: 0.8333333333333334

  62. 5

    1

    9

    Returns: 0.25636574074074076

  63. 7

    4

    10

    Returns: 0.140918370627572

  64. 5

    2

    10

    Returns: 0.22075135030864199

  65. 9

    7

    10

    Returns: 0.059531464334705075


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: