#P7495. 异位坍缩
异位坍缩
Description
The god wants to test whether his believers are loyal, and he decides to use luck as the test.
The god has prepared questions in advance. Each question has two choices: “relatively radical” and “relatively conservative”. The god has already fixed his own choices.
To test his believers, the god will uniformly choose one from all feasible ways of selecting questions (a feasible way means choosing a consecutive questions, with , where are given). Then the believers will answer each of the questions in order with either “relatively radical” or “relatively conservative”. The god will judge whether a believer is loyal based on his own choices and that believer’s answers.
The judging rules are:
- This is the first question: no matter what the answer is, the god is willing to believe the believer is loyal.
- This is not the first question: if the believer’s previous answer is the same as the god’s choice, then the god will require them to explore more advanced choices, so the believer’s answer to this question cannot be more conservative than the god’s choice; otherwise, the god will require the believer to obey him, so the believer’s answer to this question cannot be more radical than the god’s choice.
If the believer’s answers satisfy the above requirements, then the believer is loyal.
Now, the god wants to know: if a believer answers each question uniformly at random with “relatively radical” or “relatively conservative”, what is the probability that the believer is loyal? He asks you this question through Fiona, and requires you to output the result modulo . If you cannot answer in time, you will lose the god’s trust.
Simplified statement:
Given a binary string of length and .
For two binary strings of the same length , we say that is “loyal” to if and only if and satisfy:
- For any , if , then , otherwise .
You need to compute the probability that: first, uniformly choose a substring of whose length satisfies , and then uniformly choose a binary string of length , such that is “loyal” to that substring. Output the result modulo .
Input Format
The first line contains three integers , as described above.
The second line contains a string of length , representing . It is guaranteed that the string contains only characters 0 and 1.
Output Format
Output one integer in one line, representing the answer.
5 2 3
01101
338690049
17 4 13
10101110100101101
512357021
Hint
Explanation for Sample 1:
We use to denote the interval where the chosen substring lies.
-
Choose . The substring is
01, with length . There are binary strings that are “loyal” to this substring, so the probability is . -
Choose . The substring is
011, with length . There are binary strings that are “loyal” to this substring, so the probability is . -
Choose . The probability is .
-
Choose . The probability is .
-
Choose . The probability is .
-
Choose . The probability is .
-
Choose . The probability is .
So the result is $\dfrac{\dfrac{3}{4}+\dfrac{1}{2}+\dfrac{3}{4}+\dfrac{5}{8}+\dfrac{3}{4}+\dfrac{1}{2}+\dfrac{3}{4}}{7}=\dfrac{37}{56}$, which is modulo .
This problem uses bundled testdata.
- Subtask 1 ( ): .
- Subtask 2 ( ): .
- Subtask 3 ( ): Guaranteed that .
- Subtask 4 ( ): Guaranteed that .
- Subtask 5 ( ): .
- Subtask 6 ( ): .
- Subtask 7 ( ): .
- Subtask 8 ( ): No special constraints.
Constraints: for all testdata, 。
Translated by ChatGPT 5
京公网安备 11011102002149号