#P4481. [BJWC2018] 序列合并
[BJWC2018] 序列合并
Description
Scape flipped open the problemset and saw this problem:
There is a sequence and . At each step, you may merge adjacent elements (with ). The cost is the sum of those elements, and the merge produces a new element whose value is that same sum.
Find the minimum cost to merge the entire sequence into one element.
Without thinking, Scape wrote an brute force, which actually timed out (TLE). As the king of XX, Scape naturally will not bother with such a “trash” problem; please solve it.
Input Format
The first line contains an integer , the number of test cases.
For each test case, the first line contains three integers , denoting the length of sequence and the bounds on .
The second line contains integers, the sequence .
Output Format
For each test case, output one integer — the answer. If it is impossible, output .
3
3 2 2
1 2 3
3 2 3
1 2 3
4 3 3
1 2 3 4
9
6
0
Hint
Constraints:
- For of the testdata, .
- For of the testdata, .
- For of the testdata, , , .
Translated by ChatGPT 5
京公网安备 11011102002149号