Problem Statement
You are given two positive
You are going to choose x distinct integers, each between 1 and n, inclusive. The choice will be made uniformly at random. That is, each of the possible x-element subsets of the integers 1 to n is equally likely to be chosen.
Let S be the smallest integer among the x chosen ones. Compute and return the expected value of 2^S. In other words, determine the average value of 2 to the power of S, where the average is taken over all possible choices of the x distinct integers.
Definition
- Class:
- ExpectedMinimumPowerDiv2
- Method:
- findExp
- Parameters:
- int, int
- Returns:
- double
- Method signature:
- double findExp(int n, int x)
- (be sure your method is public)
Notes
- Your answer will be accepted if the absolute or relative error is at most 1e-9.
Constraints
- n will be between 1 and 50, inclusive.
- x will be between 1 and n, inclusive.
Examples
4
4
Returns: 2.0
The only possible situation is that you will choose (1, 2, 3, 4). In this case, the minimum is 1, and the expected value is 2^1 = 2.
3
2
Returns: 2.6666666666666665
There are three equally likely scenarios: you will select either {1,2} or {1,3} or {2,3}. The corresponding values of S are 1, 1, and 2, respectively. Thus, the average value of 2^S is (2^1 + 2^1 + 2^2) / 3 = 8 / 3 = 2.6666666
3
1
Returns: 4.666666666666667
10
4
Returns: 8.076190476190476
50
25
Returns: 9.906688596554163
50
1
Returns: 4.503599627370492E13
48
20
Returns: 30.38473179316371
44
1
Returns: 7.996448202006818E11
33
14
Returns: 17.874097960794778
19
2
Returns: 6131.789473684211
47
5
Returns: 1.8349815495872915E8
25
15
Returns: 4.356095889572802
15
15
Returns: 2.0
39
34
Returns: 2.320173267541689
43
9
Returns: 31195.47977138576
40
17
Returns: 21.459452348143305
43
24
Returns: 5.960055627427291
46
42
Returns: 2.1993075343934834
37
17
Returns: 12.863263871611304
48
14
Returns: 1165.9509802430277
42
7
Returns: 326042.46566621907
23
20
Returns: 2.3128176171654435
13
1
Returns: 1260.1538461538462
32
15
Returns: 10.654500717241834
36
5
Returns: 364566.94053985237
36
2
Returns: 2.1815706888571432E8
12
4
Returns: 15.34141414141414
43
23
Returns: 6.966713022856075
26
9
Returns: 41.33387335776351
45
10
Returns: 22057.14731310105
48
32
Returns: 3.6581649199398822
20
4
Returns: 432.2910216718266
45
21
Returns: 13.505501744483768
44
41
Returns: 2.1496526729084837
37
1
Returns: 7.429132620054054E9
41
33
Returns: 2.582753100279344
24
15
Returns: 3.9451198619660075
40
28
Returns: 3.264771873702332
45
13
Returns: 962.6883827166131
47
1
Returns: 5.988829291716043E12
49
23
Returns: 13.815579312933682
32
23
Returns: 3.0719298508314075
12
12
Returns: 2.0
37
37
Returns: 2.0
48
18
Returns: 74.72293857908535
29
23
Returns: 2.617220327565155
31
26
Returns: 2.4291305448146394
50
27
Returns: 7.000825657968384
39
19
Returns: 9.976346137897622
13
2
Returns: 209.69230769230768
25
11
Returns: 11.861136985686723
39
31
Returns: 2.6277734574948224
29
18
Returns: 4.111122345131654
46
9
Returns: 127743.26183065468
35
32
Returns: 2.1928189457601217
23
8
Returns: 32.62379617959105
50
50
Returns: 2.0