Statistics

Problem Statement for "BirdsCounting"

Problem Statement

In ecology, there are several ways of estimating the size of a population in a given area. We are interested in estimating the size of a population of birds. To do this, we will use the following procedure.

First, there will be a data collection phase that lasts exactly daysNumber days. Initially, all the birds are unmarked. During each day of data collection, we will catch exactly caughtPerDay birds. At the end of each day, we will examine each of the birds we have caught. If a bird is unmarked, we will mark it. If a bird is already marked, we will leave it alone (and it will remain marked). We will then release all of them back into the wild before the next day begins.

After the data collection phase is complete, we can use the number of unmarked birds caught each day to estimate the size of the population.

To help our fellow ecologists in analyzing the collected data, we must compute the probability that after daysNumber days of data collection, there will be exactly birdsMarked marked birds assuming that there are birdsNumber birds in this area. Assume that the probability of being caught is exactly the same for every bird on every day.

Definition

Class:
BirdsCounting
Method:
computeProbability
Parameters:
int, int, int, int
Returns:
double
Method signature:
double computeProbability(int birdsNumber, int caughtPerDay, int daysNumber, int birdsMarked)
(be sure your method is public)

Notes

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

Constraints

  • birdsNumber will be between 1 and 20, inclusive.
  • caughtPerDay will be between 1 and birdsNumber, inclusive.
  • daysNumber will be between 1 and 5, inclusive.
  • birdsMarked will be between 0 and birdsNumber, inclusive.

Examples

  1. 3

    1

    2

    2

    Returns: 0.6666666666666666

    After the first day, there will be exactly one marked bird. During the second day, there is a 1/3 chance that we will catch this marked bird (which means we will have 1 marked bird after 2 days), and a 2/3 chance that we will catch an unmarked bird (in which case, we will mark it and have 2 marked birds after 2 days).

  2. 9

    3

    4

    7

    Returns: 0.42061467444120504

  3. 3

    1

    5

    1

    Returns: 0.012345679012345678

  4. 13

    1

    2

    0

    Returns: 0.0

  5. 8

    3

    3

    7

    Returns: 0.2582908163265306

  6. 5

    1

    5

    1

    Returns: 0.0016000000000000005

  7. 6

    3

    3

    3

    Returns: 0.0025000000000000005

  8. 3

    2

    2

    2

    Returns: 0.3333333333333333

  9. 15

    3

    3

    6

    Returns: 0.1562130177514793

  10. 5

    1

    3

    1

    Returns: 0.04000000000000001

  11. 19

    7

    5

    15

    Returns: 0.06345877232851325

  12. 4

    4

    1

    3

    Returns: 0.0

  13. 4

    2

    2

    3

    Returns: 0.6666666666666666

  14. 4

    2

    3

    4

    Returns: 0.5277777777777778

  15. 5

    1

    2

    1

    Returns: 0.2

  16. 20

    18

    1

    18

    Returns: 1.0

  17. 11

    3

    3

    6

    Returns: 0.3023691460055096

  18. 1

    1

    1

    0

    Returns: 0.0

  19. 8

    4

    2

    8

    Returns: 0.014285714285714285

  20. 7

    5

    5

    7

    Returns: 0.9866773617988389

  21. 1

    1

    1

    1

    Returns: 1.0

  22. 9

    1

    4

    2

    Returns: 0.07681755829903977

  23. 12

    12

    3

    12

    Returns: 1.0

  24. 8

    1

    5

    5

    Returns: 0.205078125

  25. 7

    3

    4

    4

    Returns: 0.005877551020408162

  26. 7

    4

    3

    5

    Returns: 0.05877551020408163

  27. 5

    3

    2

    4

    Returns: 0.6

  28. 16

    4

    3

    10

    Returns: 0.2984784446322908

  29. 3

    3

    5

    3

    Returns: 1.0

  30. 3

    2

    5

    2

    Returns: 0.012345679012345678

  31. 9

    8

    4

    8

    Returns: 0.0013717421124828531

  32. 3

    1

    4

    3

    Returns: 0.4444444444444444

  33. 4

    2

    3

    2

    Returns: 0.027777777777777776

  34. 7

    5

    3

    5

    Returns: 0.0022675736961451243

  35. 4

    1

    4

    1

    Returns: 0.015625

  36. 18

    4

    3

    6

    Returns: 0.0017104532444786194

  37. 4

    1

    3

    3

    Returns: 0.375

  38. 20

    1

    3

    14

    Returns: 0.0

  39. 10

    1

    5

    5

    Returns: 0.3024

  40. 9

    5

    4

    8

    Returns: 0.2969041820137814

  41. 20

    8

    5

    16

    Returns: 0.031148695128343194

  42. 19

    9

    3

    18

    Returns: 0.11357185172124559

  43. 17

    9

    5

    14

    Returns: 0.002369967909006005

  44. 4

    3

    4

    3

    Returns: 0.015625

  45. 12

    9

    3

    11

    Returns: 0.17516528925619834

  46. 16

    3

    4

    12

    Returns: 0.006839923469387754

  47. 9

    4

    3

    9

    Returns: 0.09448223733938019

  48. 10

    8

    3

    8

    Returns: 4.938271604938272E-4

  49. 7

    3

    5

    5

    Returns: 0.037940191586838805

  50. 14

    8

    3

    11

    Returns: 0.04744284464564186

  51. 12

    9

    5

    11

    Returns: 0.011693138276074039

  52. 18

    8

    5

    14

    Returns: 0.0037659812026760746

  53. 11

    5

    3

    5

    Returns: 4.685069620134555E-6

  54. 3

    2

    4

    2

    Returns: 0.037037037037037035

  55. 2

    2

    3

    2

    Returns: 1.0

  56. 1

    1

    4

    1

    Returns: 1.0

  57. 7

    1

    5

    2

    Returns: 0.03748438150770512

  58. 15

    5

    3

    13

    Returns: 0.031087793325555564

  59. 10

    2

    4

    3

    Returns: 0.002282578875171468

  60. 8

    6

    4

    6

    Returns: 4.55539358600583E-5

  61. 19

    7

    5

    14

    Returns: 0.010553063029764668

  62. 19

    7

    5

    13

    Returns: 9.294088086285515E-4

  63. 19

    7

    5

    15

    Returns: 0.06345877232851325

  64. 19

    7

    5

    17

    Returns: 0.3482456585678702

  65. 19

    7

    5

    18

    Returns: 0.28512030286393125

  66. 19

    7

    5

    19

    Returns: 0.08655292058346278

  67. 10

    2

    4

    4

    Returns: 0.05008504801097394

  68. 10

    2

    4

    5

    Returns: 0.2654814814814815

  69. 10

    2

    4

    6

    Returns: 0.4332510288065844

  70. 10

    2

    4

    7

    Returns: 0.22123456790123455

  71. 10

    2

    4

    8

    Returns: 0.02765432098765432

  72. 17

    9

    5

    16

    Returns: 0.29923666251305214

  73. 17

    9

    5

    17

    Returns: 0.6554514923169341

  74. 20

    6

    5

    13

    Returns: 0.00678008576246766

  75. 20

    6

    5

    14

    Returns: 0.039847279126155724

  76. 20

    6

    5

    15

    Returns: 0.13483311440416074

  77. 20

    6

    5

    16

    Returns: 0.26541624621090926

  78. 20

    6

    5

    17

    Returns: 0.30035494805367574

  79. 20

    6

    5

    18

    Returns: 0.18722122247037307

  80. 20

    6

    5

    19

    Returns: 0.05807073960941394

  81. 20

    6

    5

    20

    Returns: 0.006799696517512649

  82. 20

    2

    5

    16

    Returns: 0.0


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: