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 nn and mm, and an array cc consisting of mm integers. You are at position 00, and you need to get to position nn. If you are at position ii, you can ride the train as follows:

  • Choose a positive integer xx such that m&x=xm\& x = x, where &\& denotes the bitwise AND operation.
  • Move from position ii to i+xi + x, paying cxc_x coins.

The cost of a trip is the total number of coins that had to be paid to get from position 00 to position nn. 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+710^9 + 7.

一座新的轻轨交通系统(LRT)在著名城市开通了。该系统是一列沿直线运行的列车。

给定两个整数 nn 和 mm,以及一个由 mm 个整数组成的数组 cc。你起始位置为 00,需要到达位置 nn。若你当前位于位置 ii,则可按如下方式乘坐列车:

  • 选择一个正整数 xx,使得 m&x=xm\& x = x,其中 &\& 表示按位与运算;
  • 从位置 ii 移动到位置 i+xi + x,并支付 cxc_x 枚金币。

一次行程的费用定义为从位置 00 到达位置 nn 所需支付的金币总数。若两次行程的移动顺序不同,或某一步所选的 xx 值不同,则认为这两次行程不同。你的任务是计算所有可能行程的费用之和。由于答案可能很大,请将结果对 109+710^9 + 7 取模后输出。

输入格式

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

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

The second line of each test case contains mm integers c1,c2,…,cmc_1, c_2, \ldots, c_m (1≤ci≤1091\le c_i\le 10^9).

It is guaranteed that the sum of nn and the sum of mm over all test cases do not exceed 2202^{20}.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 mm(1≤n,m<2201\le n, m\lt 2^{20})。

每个测试用例的第二行包含 mm 个整数 c1,c2,…,cmc_1, c_2, \ldots, c_m(1≤ci≤1091\le c_i\le 10^9)。

保证所有测试用例中 nn 的总和与 mm 的总和均不超过 2202^{20}。

输出格式

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

对于每个测试用例,输出一个数字——该问题答案对 109+710^9 + 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 44 ways to get to position nn:

  • 0→1→2→30\rightarrow 1\rightarrow 2\rightarrow 3. The cost of this trip is c1+c1+c1=6c_1 + c_1 + c_1 = 6.
  • 0→1→30\rightarrow 1\rightarrow 3. The cost of this trip is c1+c2=4c_1 + c_2 = 4.
  • 0→2→30\rightarrow 2\rightarrow 3. The cost of this trip is c2+c1=4c_2 + c_1 = 4.
  • 0→30\rightarrow 3. The cost of this trip is c3=1c_3 = 1.

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

在第一个测试用例中,共有 44 种方式到达位置 nn:

  • 0→1→2→30\rightarrow 1\rightarrow 2\rightarrow 3。该路径的花费为 c1+c1+c1=6c_1 + c_1 + c_1 = 6。
  • 0→1→30\rightarrow 1\rightarrow 3。该路径的花费为 c1+c2=4c_1 + c_2 = 4。
  • 0→2→30\rightarrow 2\rightarrow 3。该路径的花费为 c2+c1=4c_2 + c_1 = 4。
  • 0→30\rightarrow 3。该路径的花费为 c3=1c_3 = 1。

因此,答案为 6+4+4+1=156 + 4 + 4 + 1 = 15。

输入解题思路,AI测评打分。不知道怎么写?

首页