#P3750. [六省联考 2017] 分手是祝愿

    ID: 1322 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划,dp递推2017各省省选枚举,暴力期望

[六省联考 2017] 分手是祝愿

Description

Zeit und Raum trennen dich und mich. Time and space separate you and me.

B-kun is playing a game with nn lights and nn switches. The nn lights have initial states and are indexed by the positive integers from 11 to nn.

Each light has two states, on and off. We use 11 to indicate the light is on and 00 to indicate it is off. The goal of the game is to turn all lights off.

When operating the ii-th switch, the states of all lights whose indices are divisors of ii (including 11 and ii) are toggled, i.e., on becomes off, and off becomes on.

B-kun finds this game difficult, so he considers the following strategy: at each step, uniformly at random choose one switch to operate, until all lights are off.

This strategy may require many operations, so B-kun thinks of the following optimization. If, in the current state, it is possible to turn all lights off by pressing at most kk switches, then he will stop acting randomly and directly choose a method with the minimum number of operations (which is clearly at most kk) to press those switches.

B-kun wants to know the expected number of operations under this strategy (that is, act randomly first, and finally, if at most kk steps suffice, use the method with the minimum number of operations).

This expectation may be large, but B-kun observes that the expectation multiplied by n!n! is always an integer, so he only needs this integer modulo 100003100003.

Input Format

The first line contains two integers n,kn, k.
The next line contains nn integers, each being 00 or 11, where the ii-th integer indicates the initial state of the ii-th light.

Output Format

Output one line: the expectation of the number of operations multiplied by n!n!, modulo 100003100003.

4 0
0 0 1 1

512
5 0
1 0 1 1 1
5120

Hint

For 0%0\% of the testdata, the input is identical to the sample.
For an additional 30%30\% of the testdata, n10n \leq 10.
For an additional 20%20\% of the testdata, n100n \leq 100.
For an additional 30%30\% of the testdata, n1000n \leq 1000.
For 100%100\% of the testdata, 1n100000,0kn1 \leq n \leq 100000, 0 \leq k \leq n.
For each of the above parts of the testdata, half of the testdata satisfies k=nk = n.

Translated by ChatGPT 5