Connection Status:
Competition Arena > TheKFactor
SRM 682 · 2016-01-04 · by zxqfl · Math
Class Name: TheKFactor
Return Type: double
Method Name: expectedScore
Arg Types: (vector<int>)
Problem Statement

Problem Statement

Bob has been selected to compete on a game show called The K Factor. The rules are as follows: The game is played on a strip of N cells that goes from the left to the right. The cells are numbered from 0 to N-1, starting on the left end. Additionally, each cell of the grid has a value written on it. You are given these values in the int[] values. Bob starts the game on cell 0. During the game he will sometimes be asked to make a move. Each time he is asked to do so, he has two options: he can either end the whole game (remaining where he stands at that moment), or move one cell to the right. The amount he wins is the value written in the cell where he stands at the end of the game. Of course, there is a catch. At the beginning of the game, the host of the show generates a secret integer K. The value of K is always between 0 and N-1, inclusive. K is then used as the maximum number of times the host will ask Bob to make a move. (If Bob actually makes K moves to the right without deciding to end the game, after Bob's K-th move the host will terminate the game. In this case Bob still gets the amount written in the cell where he finished the game.)

The host of the show keeps the value of K secret from Bob. However, Bob does have some information about K. He knows that K is chosen at random. He does not know the exact probability distribution used by the host when generating K, but he knows one property of this probability distribution: for each positive integer X, the chance that K is less than X is at most X/N.

Assume that Bob uses the strategy that maximizes the expected value of the amount he wins against the worst possible distribution of values for K. By a "strategy", we mean that Bob selects, for each cell, the probability that he will stop at that cell if he reaches it. Please find the expected value of the amount Bob will win.

Notes

  • Your answer will be considered correct if its absolute or relative error does not exceed 10^(-4).

Constraints

  • values will contain between 1 and 50 elements, inclusive.
  • Each element of values will be between 0 and 10000, inclusive.
Examples
0)
{1, 2, 3, 4, 5}
Returns: 3.0

Bob should never end this game early. The unique worst-case distribution is {1/5, 1/5, 1/5, 1/5, 1/5}. The expected value of Bob's score is 1 * (1/5) + 2 * (1/5) + 3 * (1/5) + 4 * (1/5) + 5 * (1/5) = 3.

1)
{5, 9, 0, 34}
Returns: 8.777778

Bob's optimal strategy can be succinctly described as follows: stop at cell 1 (amount=9) with probability 5/9 and to continue until cell 3 (amount=34) with probability 4/9. One possible worst-case distribution against this strategy is {0, 0, 3/4, 1/4}. Another worst-case distribution is {1/4, 0, 1/2, 1/4}. In both cases, the expected value of Bob's score is 79/9.

2)
{10000, 0, 100}
Returns: 10000.0
3)
{4374, 5909, 7194, 8367, 1328, 9373, 6067, 7097, 7631, 4841, 2584, 6877, 9775, 2831, 1916, 3253, 8670, 736, 9016, 825, 5002, 8739, 3735, 3262, 5050, 2146, 9273, 5163, 4015, 3174, 1424, 7716, 4162, 9960, 1880, 4320, 7047, 3253, 8702}
Returns: 8352.585573
4)
{4814, 4710, 5035, 4513, 5046, 4381, 5402, 4372, 6113, 4354, 6205, 4271, 6517, 3989, 6804, 3533, 6811, 3032, 7138, 2848, 7277, 2574, 7278, 2456, 7345, 2239, 7417, 2035, 7519, 1977, 7802, 1920, 8449, 1336, 8612, 1233, 9264, 902, 9284, 690, 9558, 408, 9608, 208, 9661, 139, 9797, 127, 9910, 99}
Returns: 6077.793513

Submissions are judged against all 41 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class TheKFactor with a public method double expectedScore(vector<int> values) · 41 test cases · 2 s / 256 MB per case

Submitting as anonymous