#P8096. [USACO22JAN] Drought G

    ID: 9203 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划 DPUSACO2022动态规划优化前缀和

[USACO22JAN] Drought G

Problem Description

All the grass in Farmer John’s pasture has dried up in a severe drought. After hours of despair and thinking, FJ comes up with a brilliant idea: buy corn to feed his precious cows.

FJ’s NN cows (1N1001 \leq N \leq 100) are standing in a line. The hunger level of the ii-th cow in the line is a non-negative integer hih_i. Since FJ’s cows are social animals, they insist on eating together. The only way for FJ to decrease the cows’ hunger levels is to choose two adjacent cows ii and i+1i+1 and feed each of them one bag of corn, which decreases both of their hunger levels by 1.

FJ wants to feed his cows until all cows have the same non-negative hunger level. Although he does not know the exact hunger levels of his cows, he knows an upper bound for each cow; specifically, the hunger level hih_i of the ii-th cow is at most HiH_i (0Hi10000 \le H_i \le 1000).

Your task is to compute the number of NN-tuples [h1,h2,,hN][h_1,h_2,\ldots,h_N] that satisfy the above upper bounds and for which it is possible for FJ to achieve his goal. Output the answer modulo 109+710^9+7.

Input Format

The first line of input contains NN.

The second line contains H1,H2,,HNH_1, H_2, \ldots, H_N.

Output Format

Output the number of valid NN-tuples of hunger levels, modulo 109+710^9+7.

3
9 11 7
241
4
6 8 5 9
137

Hint

[Sample Explanation]

There are (9+1)(11+1)(7+1)(9+1)\cdot (11+1)\cdot (7+1) different 3-tuples hh that are consistent with HH.

h=[8,10,5]h = [8,10,5] is one such tuple. In this case, it is possible to make all cows have the same hunger level: feed cows 22 and 33 two bags of corn each, then feed cows 11 and 22 five bags of corn each, and all cows will end up with hunger level 33.

h=[0,1,0]h = [0,1,0] is another tuple. In this case, it is not possible to make the cows’ hunger levels equal.

[Constraints]

  • In test points with even indices, NN is even. In test points with odd indices, NN is odd.

  • Test points 3-4 satisfy N6N \le 6 and Hi10H_i \le 10.

  • Test points 5-10 satisfy N50N \le 50 and Hi100H_i \le 100.

  • Test points 11-20 have no additional constraints.

Translated by ChatGPT 5