#P8504. 「CGOI-2」No will to break
「CGOI-2」No will to break
Background
-Spread-by-missing-their-people's-thoughts-oh-thoughts-belief-
-Their-paths-missing-cut-off-oh-void-all-diversity-
-Within-the-same-kind-will-missing-container-forever-submit-oh-
-Put-into-matter-all-missing-yi-hollow-shell-seal-
Problem Description
A battle consists of moments. At moment , the probability of being safe is .
During safe moments, you may perform "gathering". It is required that in every consecutive moments, at least moments perform gathering. Under this condition, you want the number of moments that perform gathering to be as small as possible. If this condition cannot be satisfied, then the number of gathering moments is considered to be . Find the expected number of gathering moments, and output the answer modulo .
Input Format
The first line contains three integers , with meanings as described above.
The next lines: the -th line contains two integers , meaning that at moment , the probability of being safe is .
Output Format
Output one integer, the expected value modulo .
5 3 1
1 0
2 0
3 0
4 0
114514 0
1
3 2 1
1 0
1 1
1 1
1
4 2 1
3 2
2 0
1 1
3 1
249561090
15 5 2
4 0
2 0
3 1
0 1
1 4
2 0
0 4
1 4
0 4
1 0
2 2
4 1
0 4
1 0
4 0
63887640
Hint
Sample Explanation:
Use 1 to indicate that the current moment is safe, and 0 otherwise.
For sample 1, the safety sequence can only be 11111. In every consecutive three moments, at least one moment must be used for gathering. You can choose moment to gather, which satisfies the condition. The number of gathering moments is , and it can be proven that it cannot be less than . Since there is only one possible case, the expectation is also .
For sample 2, the safety sequences 100, 101, 110, 111 have equal probability, all being . The numbers of gathering moments are respectively, so the expectation is .
Constraints:
This problem uses bundled testdata.
| ID | Limit | Score |
|---|---|---|
| 0 | 10pts | |
| 1 | , or | |
| 2 | 30pts | |
| 3 | None | 50pts |
For of the testdata, , , , .
Translated by ChatGPT 5