CF2267G.New LRT
省选/NOI-
通过率:0%
时间限制:2.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 cx 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 109+7.
一座新的轻轨交通系统(LRT)在著名城市开通了。该系统是一列沿直线运行的列车。
给定两个整数 n 和 m,以及一个由 m 个整数组成的数组 c。你起始位置为 0,需要到达位置 n。若你当前位于位置 i,则可按如下方式乘坐列车:
- 选择一个正整数 x,使得 m&x=x,其中 & 表示按位与运算;
- 从位置 i 移动到位置 i+x,并支付 cx 枚金币。
一次行程的费用定义为从位置 0 到达位置 n 所需支付的金币总数。若两次行程的移动顺序不同,或某一步所选的 x 值不同,则认为这两次行程不同。你的任务是计算所有可能行程的费用之和。由于答案可能很大,请将结果对 109+7 取模后输出。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
The first line of each test case contains two integers n and m (1≤n,m<220).
The second line of each test case contains m integers c1,c2,…,cm (1≤ci≤109).
It is guaranteed that the sum of n and the sum of m over all test cases do not exceed 220.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
每个测试用例的第一行包含两个整数 n 和 m(1≤n,m<220)。
每个测试用例的第二行包含 m 个整数 c1,c2,…,cm(1≤ci≤109)。
保证所有测试用例中 n 的总和与 m 的总和均不超过 220。
输出格式
For each test case, output one number — the answer to the problem modulo 109+7.
对于每个测试用例,输出一个数字——该问题答案对 109+7 取模的结果。
输入输出样例
输入#1
4 3 3 2 2 1 4 5 3 1 2 4 5 5 3 9 1 5 8 3 1000000000 1000000000 1000000000
输出#1
15 16 271 999997081
说明/提示
In the first test case, there are 4 ways to get to position n:
- 0→1→2→3. The cost of this trip is c1+c1+c1=6.
- 0→1→3. The cost of this trip is c1+c2=4.
- 0→2→3. The cost of this trip is c2+c1=4.
- 0→3. The cost of this trip is c3=1.
Thus, the answer is 6+4+4+1=15.
在第一个测试用例中,共有 4 种方式到达位置 n:
- 0→1→2→3。该路径的花费为 c1+c1+c1=6。
- 0→1→3。该路径的花费为 c1+c2=4。
- 0→2→3。该路径的花费为 c2+c1=4。
- 0→3。该路径的花费为 c3=1。
因此,答案为 6+4+4+1=15。
输入解题思路,AI测评打分。不知道怎么写?