CF2226A.Disturbing Distribution

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given an array [a1,a2,…,an][a_1, a_2, \ldots, a_n]. You wish to make the array empty by performing the following operation any number of times:

  • Select any sequence of indices 1≤i1<i2<…<ik≤∣a∣1 \le i_1 \lt i_2 \lt \ldots \lt i_k \le |a| (note that ∣a∣|a| denotes the current length of the array aa) such that $$a_{i_1} \le a_{i_2} \le \ldots \le a_{i_k}$$
  • Remove the elements ai1,ai2,…,aika_{i_1}, a_{i_2}, \ldots, a_{i_k} from the array aa.
  • This operation incurs a cost equal to ai1×ai2×⋯×aika_{i_1} \times a_{i_2} \times \cdots \times a_{i_k}.

Determine the minimum total cost required to remove all the elements from the array aa. Note that the total cost is equal to the sum of costs incurred over all the operations performed.

As the answer can be very large, report the answer modulo 676 767 677676\,767\,677.

给你一个数组 [a1,a2,…,an][a_1, a_2, \ldots, a_n]。你需要通过执行以下操作若干次,使该数组变为空:

  • 任选一串下标序列 1≤i1<i2<…<ik≤∣a∣1 \le i_1 \lt i_2 \lt \ldots \lt i_k \le |a|(注意:∣a∣|a| 表示当前数组 aa 的长度),满足

    a_i_1lea_i_2leldotslea_i_ka\_{i\_1} \\le a\_{i\_2} \\le \\ldots \\le a\_{i\_k}

  • 将数组 aa 中的元素 ai1,ai2,…,aika_{i_1}, a_{i_2}, \ldots, a_{i_k} 删除;
  • 此操作产生的代价为 ai1×ai2×⋯×aika_{i_1} \times a_{i_2} \times \cdots \times a_{i_k}。

求将数组 aa 中所有元素全部删除所需的最小总代价。注意:总代价等于所有执行的操作所产生代价之和。

由于答案可能非常大,请将结果对 676 767 677676\,767\,677 取模后输出。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤5001 \le t \le 500). The description of the test cases follows.

The first line of each testcase contains a single integer nn (1≤n≤1001 \le n \le 100) — the length of the array aa.

The second line of each testcase contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤1001 \le a_i \le 100) — the elements of the array.

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

每个测试用例的第一行包含一个整数 nn(1≤n≤1001 \le n \le 100)—— 数组 aa 的长度。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤1001 \le a_i \le 100)—— 数组的元素。

输出格式

For each testcase, output a single integer — the minimum total cost required to make the array aa empty.

As the answer may be large, output the answer modulo 676 767 677676\,767\,677.

对于每个测试用例,输出一个整数——使数组 aa 变为空所需的最小总成本。

由于答案可能很大,请对 676 767 677676\,767\,677 取模后输出答案。

输入输出样例

  • 输入#1

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

    输出#1

    7
    6
    1

说明/提示

For the first testcase,

  • Operation 1: Choose i1=1i_1 = 1, i2=2i_2 = 2, and i3=4i_3 = 4. This incurs a cost of 1⋅2⋅2=41 \cdot 2 \cdot 2 = 4. After deleting the elements at these indices, the array becomes a=[1,3]a = [1, 3].

  • Operation 2: Choose i1=1i_1 = 1 and i2=2i_2 = 2. This incurs a cost of 1⋅3=31 \cdot 3 = 3. After deleting the elements at these indices, the array becomes empty.

Thus, the total cost is equal to 4+3=74 + 3 = 7. It can be shown that this is the minimum possible total cost.

对于第一个测试用例:

  • 操作 1:选择 i1=1i_1 = 1、i2=2i_2 = 2 和 i3=4i_3 = 4。此次操作的代价为 1⋅2⋅2=41 \cdot 2 \cdot 2 = 4。删除这些下标处的元素后,数组变为 a=[1,3]a = [1, 3]。

  • 操作 2:选择 i1=1i_1 = 1 和 i2=2i_2 = 2。此次操作的代价为 1⋅3=31 \cdot 3 = 3。删除这些下标处的元素后,数组变为空。

因此,总代价等于 4+3=74 + 3 = 7。可以证明这是可能的最小总代价。

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

首页