Problem Statement
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
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).
9
3
4
7
Returns: 0.42061467444120504
3
1
5
1
Returns: 0.012345679012345678
13
1
2
0
Returns: 0.0
8
3
3
7
Returns: 0.2582908163265306
5
1
5
1
Returns: 0.0016000000000000005
6
3
3
3
Returns: 0.0025000000000000005
3
2
2
2
Returns: 0.3333333333333333
15
3
3
6
Returns: 0.1562130177514793
5
1
3
1
Returns: 0.04000000000000001
19
7
5
15
Returns: 0.06345877232851325
4
4
1
3
Returns: 0.0
4
2
2
3
Returns: 0.6666666666666666
4
2
3
4
Returns: 0.5277777777777778
5
1
2
1
Returns: 0.2
20
18
1
18
Returns: 1.0
11
3
3
6
Returns: 0.3023691460055096
1
1
1
0
Returns: 0.0
8
4
2
8
Returns: 0.014285714285714285
7
5
5
7
Returns: 0.9866773617988389
1
1
1
1
Returns: 1.0
9
1
4
2
Returns: 0.07681755829903977
12
12
3
12
Returns: 1.0
8
1
5
5
Returns: 0.205078125
7
3
4
4
Returns: 0.005877551020408162
7
4
3
5
Returns: 0.05877551020408163
5
3
2
4
Returns: 0.6
16
4
3
10
Returns: 0.2984784446322908
3
3
5
3
Returns: 1.0
3
2
5
2
Returns: 0.012345679012345678
9
8
4
8
Returns: 0.0013717421124828531
3
1
4
3
Returns: 0.4444444444444444
4
2
3
2
Returns: 0.027777777777777776
7
5
3
5
Returns: 0.0022675736961451243
4
1
4
1
Returns: 0.015625
18
4
3
6
Returns: 0.0017104532444786194
4
1
3
3
Returns: 0.375
20
1
3
14
Returns: 0.0
10
1
5
5
Returns: 0.3024
9
5
4
8
Returns: 0.2969041820137814
20
8
5
16
Returns: 0.031148695128343194
19
9
3
18
Returns: 0.11357185172124559
17
9
5
14
Returns: 0.002369967909006005
4
3
4
3
Returns: 0.015625
12
9
3
11
Returns: 0.17516528925619834
16
3
4
12
Returns: 0.006839923469387754
9
4
3
9
Returns: 0.09448223733938019
10
8
3
8
Returns: 4.938271604938272E-4
7
3
5
5
Returns: 0.037940191586838805
14
8
3
11
Returns: 0.04744284464564186
12
9
5
11
Returns: 0.011693138276074039
18
8
5
14
Returns: 0.0037659812026760746
11
5
3
5
Returns: 4.685069620134555E-6
3
2
4
2
Returns: 0.037037037037037035
2
2
3
2
Returns: 1.0
1
1
4
1
Returns: 1.0
7
1
5
2
Returns: 0.03748438150770512
15
5
3
13
Returns: 0.031087793325555564
10
2
4
3
Returns: 0.002282578875171468
8
6
4
6
Returns: 4.55539358600583E-5
19
7
5
14
Returns: 0.010553063029764668
19
7
5
13
Returns: 9.294088086285515E-4
19
7
5
15
Returns: 0.06345877232851325
19
7
5
17
Returns: 0.3482456585678702
19
7
5
18
Returns: 0.28512030286393125
19
7
5
19
Returns: 0.08655292058346278
10
2
4
4
Returns: 0.05008504801097394
10
2
4
5
Returns: 0.2654814814814815
10
2
4
6
Returns: 0.4332510288065844
10
2
4
7
Returns: 0.22123456790123455
10
2
4
8
Returns: 0.02765432098765432
17
9
5
16
Returns: 0.29923666251305214
17
9
5
17
Returns: 0.6554514923169341
20
6
5
13
Returns: 0.00678008576246766
20
6
5
14
Returns: 0.039847279126155724
20
6
5
15
Returns: 0.13483311440416074
20
6
5
16
Returns: 0.26541624621090926
20
6
5
17
Returns: 0.30035494805367574
20
6
5
18
Returns: 0.18722122247037307
20
6
5
19
Returns: 0.05807073960941394
20
6
5
20
Returns: 0.006799696517512649
20
2
5
16
Returns: 0.0