#P2476. [SCOI2008] 着色方案

    ID: 1488 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>动态规划,dp搜索2008四川各省省选记忆化搜索

[SCOI2008] 着色方案

Description

There are nn wooden blocks arranged in a row, numbered from 11 to nn from left to right.

You have kk colors of paint, and the ii-th color is enough to paint cic_i blocks.

All the paint is just enough to cover all blocks, i.e., i=1kci=n\sum_{i=1}^k c_i = n.

Since it looks bad if two adjacent blocks have the same color, you want to count the number of colorings in which any two adjacent blocks have different colors.

Since the answer may be large, please output the result modulo 109+710^9+7.

Input Format

The first line contains an integer kk, the number of colors.

The second line contains kk integers c1,c2,,ckc_1, c_2, \dots, c_k, where cic_i is the number of blocks that can be painted with the ii-th color.

Output Format

Output a single integer, the answer modulo 109+710^9+7.

3
1 2 3
10
5
2 2 2 2 2
39480
10
1 1 2 2 3 3 4 4 5 5

85937576

Hint

  • For 50% of the testdata, 1k51 \leq k \leq 5, 1ci31 \leq c_i \leq 3.
  • For 100% of the testdata, 1k151 \leq k \leq 15, 1ci51 \leq c_i \leq 5.

Translated by ChatGPT 5