#P4495. [HAOI2018] 奇怪的背包

    ID: 3443 远端评测题 2000ms 500MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划,dp2018河南各省省选O2优化枚举,暴力概率论,统计

[HAOI2018] 奇怪的背包

Description

Xiao C is very good at knapsack problems. He has a strange knapsack with a parameter PP. After he puts some items into this knapsack, the knapsack’s weight is the total volume of the items modulo PP.

Now there are nn types of items with different volumes. The ii-th type has volume ViV_i, and each type has an unlimited supply. He will make qq queries. For each query, a weight wiw_i is given. You need to answer how many ways there are to put items so that the weight of an initially empty knapsack becomes wiw_i. Note that two ways are considered different if and only if the types of items used are different, regardless of how many of each type are used. It is not hard to see that the total number of ways is 2n2^n.

Since the answer may be large, you only need to output it modulo 109+710^9 + 7.

Input Format

The first line contains three integers n,q,Pn, q, P, as described above.

The next line contains nn integers denoting ViV_i.

The next line contains qq integers denoting wiw_i.

Output Format

Output qq lines, each containing one integer, the answer for that query.

3 3 6
1 3 4
5 2 3
5
6
6

Hint

HAOI2018 round1 T1

Translated by ChatGPT 5