第 1123 场 Codeforces Round(Div. 2)
G
新的轻轨
New LRT
Codeforces
2600
原题
← F2→

新的轻轨AI (CI翻译)

A new LRT (light rail transit) has opened in the famous city. It is a train that moves along a straight line.

翻译中…

You are given two numbers $n$ and $m$, and an array $c$ consisting of $m$ integers. You are at position $0$, and you need to get to position $n$. If you are at position $i$, you can ride the train as follows:

翻译中…
  • Choose a positive integer $x$ such that $m\& x = x$, where $\&$ denotes the bitwise AND operation.
  • Move from position $i$ to $i + x$, paying $c_x$ coins.
翻译中…

The

翻译中…

cost

翻译中…

of a trip is the total number of coins that had to be paid to get from position $0$ to position $n$. Two trips are considered different if the order of moves differs or the moves themselves differ. Your task is to determine the sum of the

翻译中…

costs

翻译中…

of all possible trips. Since the answer may be large, output it modulo $10^9 + 7$.

翻译中…

Input

输入格式

AI (CI翻译)

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

每个输入包含多组测试用例。第一行包含测试用例数量 $t$($1 \le t \le 10^4$)。接下来是各测试用例的描述。AI (CI翻译)

The first line of each test case contains two integers $n$ and $m$ ($1\le n, m\lt 2^{20}$).

每个测试用例的第一行包含两个整数 $n$ 和 $m$($1\le n, m\lt 2^{20}$)。AI (CI翻译)

The second line of each test case contains $m$ integers $c_1, c_2, \ldots, c_m$ ($1\le c_i\le 10^9$).

每个测试用例的第二行包含 $m$ 个整数 $c_1, c_2, \ldots, c_m$($1\le c_i\le 10^9$)。AI (CI翻译)

It is guaranteed that the sum of $n$ and the sum of $m$ over all test cases do not exceed $2^{20}$.

保证所有测试用例的 $n$ 之和与 $m$ 之和均不超过 $2^{20}$。AI (CI翻译)

Output

输出格式

AI (CI翻译)

For each test case, output one number — the answer to the problem modulo $10^9 + 7$.

对于每个测试用例,输出一个数——问题的答案对 $10^9 + 7$ 取模后的结果。AI (CI翻译)

Note

说明

AI (CI翻译)

In the first test case, there are $4$ ways to get to position $n$:

在第一个测试用例中,有 $4$ 种方式到达位置 $n$:AI (CI翻译)

  • $0\rightarrow 1\rightarrow 2\rightarrow 3$. The cost of this trip is $c_1 + c_1 + c_1 = 6$.
  • $0\rightarrow 1\rightarrow 3$. The cost of this trip is $c_1 + c_2 = 4$.
  • $0\rightarrow 2\rightarrow 3$. The cost of this trip is $c_2 + c_1 = 4$.
  • $0\rightarrow 3$. The cost of this trip is $c_3 = 1$.
  • $0\rightarrow 1\rightarrow 2\rightarrow 3$。这次行程的花费为 $c_1 + c_1 + c_1 = 6$。
  • $0\rightarrow 1\rightarrow 3$。这次行程的花费为 $c_1 + c_2 = 4$。
  • $0\rightarrow 2\rightarrow 3$。这次行程的花费为 $c_2 + c_1 = 4$。
  • $0\rightarrow 3$。这次行程的花费为 $c_3 = 1$。
AI (CI翻译)

Thus, the answer is $6 + 4 + 4 + 1 = 15$.

因此,答案为 $6 + 4 + 4 + 1 = 15$。AI (CI翻译)

样例

Input #1
4
3 3
2 2 1
4 5
3 1 2 4 5
5 3
9 1 5
8 3
1000000000 1000000000 1000000000
Output #1
15
16
271
999997081
InputCopy OutputCopy
题目信息
题号
2267G
时间限制
2 s
内存限制
512 MB
标签
分治
动态规划
FFT

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。