#P5326. [ZJOI2019] 开关
[ZJOI2019] 开关
Description
Jiutiao Keliang is a playful girl.
One day, she and her good friend Brother Fahai went to play an escape room. In front of them are switches, and at the beginning every switch is in the off state. To pass this level, the switches must reach a specified state. The target state is given by a binary array of length . means the -th switch needs to be off in the end, and means the -th switch needs to be on in the end.
However, as challengers, Keliang and Fahai do not know . So they decided to use a safer method: pressing randomly. Based on the shape and position of the switches, they used some “mystic” methods to assign each switch a weight (). Each time, they choose and press one switch with probability proportional to (the probability that the -th switch is chosen is ). After a switch is pressed, its state is flipped: on becomes off, and off becomes on. Note that each round of selection is completely independent.
During the process of pressing switches, once the current states of switches match , the door in front of Keliang and Fahai will open. They will immediately stop pressing switches and move on to the next level. As a very lucky person, Keliang opened the door after pressing times. To feel how good her luck was, she wants you to help her compute: using this random pressing method, what is the expected number of presses needed to pass this level?
Input Format
The first line contains an integer , representing the number of switches.
The second line contains integers (), representing the target state of each switch.
The third line contains integers , representing the weight of each switch.
Output Format
Output one line with one integer, representing the answer modulo . That is, if the answer in simplest fractional form is (, , ), you should output .
2
1 1
1 1
4
8
1 1 0 0 1 1 0 0
1 2 3 4 5 6 7 8
858924815
Hint
[Sample Explanation #1]
In the first two presses, there is a probability of to reach , and a probability of to return to the initial state. Therefore, the expected number of switch presses is:
$$\sum^{+\infty}_{i=1}2i\times \left(\frac12\right)^i=4$$[Constraints and Notes]
| Test Point | Other Notes | Test Point | Other Notes | ||
|---|---|---|---|---|---|
| None | |||||
| None |
For of the testdata, it is guaranteed that , , and .
Translated by ChatGPT 5
京公网安备 11011102002149号