#P6036. Expected Affection over Maximal Continuous Knowledge Segments
Expected Affection over Maximal Continuous Knowledge Segments
Expected Affection over Maximal Continuous Knowledge Segments
At each time i (1-indexed), Ryoku receives a new piece of knowledge with an actual value wi. Although she never opts out of learning, she masters a piece of knowledge with probability pi independently. However, if she masters too many consecutive pieces of knowledge, her affection for them changes. In particular, for any continuous interval of time [l, r] during which she has mastered all the knowledge, the "affection" that she feels for that maximal (i.e. not contained in any longer interval of mastered knowledge) segment is defined as:
where 0 < a, b < 1 are given parameters. Note that in the formula the exponent is written in LaTeX format.
Your task is to calculate the expected sum of the affection over all maximal continuous segments of time in which Ryoku masters the knowledge. A segment is considered maximal if it is not contained in a longer continuous segment of mastered knowledge. For a segment [l, r] to be maximal, it must satisfy the following conditions:
- If l > 1, then the knowledge at time l-1 is not mastered (with probability 1-pl-1); otherwise, if l = 1, no left restriction applies.
- If r < n, then the knowledge at time r+1 is not mastered (with probability 1-pr+1); otherwise, if r = n, no right restriction applies.
Hence, the contribution of a segment [l, r] is:
$$\text{Contribution} = \Bigl(\mathbf{1}_{\{l=1\}} + \mathbf{1}_{\{l>1\}}(1-p_{l-1})\Bigr) \cdot \Bigl(\mathbf{1}_{\{r=n\}} + \mathbf{1}_{\{r<n\}}(1-p_{r+1})\Bigr) \cdot \Bigl(\prod_{i=l}^{r} p_i\Bigr) \cdot f(l,r), $$and the expected total affection is the sum of the contributions for every possible segment [l, r] (where 1 ≤ l ≤ r ≤ n).
Input Format:
The first line contains an integer n, the number of time instants.
The second line contains two real numbers a and b (with 0 < a, b < 1).
Each of the following n lines contains two real numbers: pi and wi, representing the probability of mastering the knowledge and the value of the knowledge at time i respectively.
Output Format:
Print the expected total affection, computed as described above. Your answer will be accepted if it has an absolute or relative error of at most 10-6.
inputFormat
The input consists of multiple lines:
- The first line contains an integer n (the number of knowledge instances).
- The second line contains two real numbers a and b (0 < a, b < 1).
- Each of the following n lines contains two real numbers: pi and wi.
outputFormat
Output a real number representing the expected total affection. The result must be accurate within an absolute or relative error of 10-6.
sample
3
0.5 0.5
0.5 10
0.5 20
0.5 30
23.32107