luogu#P9824. [ICPC2020 Shanghai R] Fountains

[ICPC2020 Shanghai R] Fountains

题目描述

Suppose you and your teammate Mixsx will attend the Namomo Camp. The Namomo Camp will happen in nn consecutive days. We name the ii-th day as day ii (1in1\le i\le n). The cost of day ii is sis_i.

Unfortunately, the schedule of the Namomo Camp conflicts with Mixsx's final exams. Mixsx has final exams every day between day LL and day RR. The exact value of LL and RR have not been announced by his college so we assume that every pair of integers LL and RR satisfying 1LRn1\le L\le R\le n will be chosen with probability 1/(n(n+1)/2)1/(n(n+1)/2). He decides to take all the exams and thus be absent from the Namomo Camp from day LL to day RR. His loss\textit{loss} will be i=LRsi\sum_{i=L}^R s_i in this case.

As Mixsx's teammate, you want Mixsx to give up his final exams and come back to the Namomo Camp. You can prepare kk plans before LL and RR are announced. In the ii-th plan (1ik1\le i\le k), you shut the electricity off to his college every day from day lil_i to day rir_i. You can choose the values of lil_i and rir_i as long as they are two integers satisfying 1lirin1\le l_i\le r_i\le n.

Once LL and RR are announced, you can choose a plan xx (1xk1\le x\le k) such that LlxrxRL\le l_x\le r_x\le R. Then Mixsx will come back to the Namomo Camp on every day from day lxl_x to day rxr_x. His loss becomes i=LRsii=lxrxsi\sum_{i=L}^R s_i-\sum_{i=l_x}^{r_x} s_i in this case. You will choose a plan that minimizes Mixsx's loss. If no plan xx satisfies LlxrxRL\le l_x\le r_x\le R, Mixsx will attend his final exams normally and his loss is i=LRsi\sum_{i=L}^R s_i.

Please calculate the minimum possible expected loss anskans_k of Mixsx if you choose the kk plans optimally. Output anskn(n+1)/2ans_k\cdot n(n+1)/2 for every kk from 11 to n(n+1)/2n(n+1)/2.

Formally, given a list of nn numbers sis_i (1in)(1 \leq i \leq n), define a loss function C(L,R)=i=LRsiC(L, R) = \sum_{i=L}^R s_i. Given an integer kk (1kn(n+1)/21 \leq k \leq n (n + 1) / 2), you should select 2k2k integers l1,,lk,r1,,rkl_1, \ldots, l_k, r_1,\ldots, r_k satisfying 1lirin1\le l_i\le r_i\le n for all 1ik1 \leq i \leq k, such that

$$\sum_{1\leq L\leq R\leq n} \left[C(L, R) - \max_{1\le i\le k, L \leq l_i \leq r_i \leq R} C(l_i, r_i) \right] $$

is minimized. ($\max_{1\le i\le k, L \leq l_i \leq r_i \leq R} C(l_i, r_i)$ is defined as 00 if no ii satisfies 1ik1\le i\le k and LliriRL \leq l_i \leq r_i \leq R.) Output the minimized value for every integer kk in [1,n(n+1)/2][1, n(n + 1) / 2].

输入格式

The first line contains an integer n (1n9)n~(1 \leq n \leq 9). The second line contains nn space separated integers si (1si109)s_i~(1 \leq s_i \leq 10^9).

输出格式

The output contains n(n+1)/2n (n + 1) / 2 integers in their own lines, the expectations when k=1,,n(n+1)/2k = 1, \ldots, n (n + 1) / 2 multiplied by n(n+1)/2n (n + 1) / 2. It can be shown that the results are always integers.

题目大意

给出一个长度为 nn 的序列 ss,定义 C(l,r)=i=lrsiC(l,r)=\sum\limits_{i=l}^r s_i

对于每个 1kn(n+1)/21 \le k \le n(n+1)/2,找出 kk 个二元组 (l1,r1),,(lk,rk)(l_1,r_1),\dots,(l_k,r_k),满足 1lirin1 \le l_i \le r_i \le n,最小化:

$$\sum_{1\leq L\leq R\leq n} \left[C(L, R) - \max_{1\le i\le k, L \leq l_i \leq r_i \leq R} C(l_i, r_i) \right] $$

您只需要对于每个 kk 输出对应的值,不需要输出方案。

1
1
0
2
13 24
26
13
0
3
6 4 7
33
21
12
8
4
0

提示

For the first test case, we only need to consider the case k=1k = 1. We can only choose l1=r1=1l_1=r_1=1. Then the expected loss is C(1,1)C(1,1)=0C(1, 1) - C(1, 1) = 0 and the result is 0×1×(2)/2=00 \times 1 \times (2) / 2 = 0.

For the third test case, consider the case when k=3k = 3. We choose l1=r1=1l_1=r_1=1, l2=r2=3l_2=r_2=3 and l3=1,r3=3l_3=1, r_3=3. The expected loss is 22. And the result is 2×6=122 \times 6 = 12.