#P17284. 「IXOI R2」想不出来

    ID: 19691 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 显示难度提高+/省选− 上传者: 标签>动态规划 DP洛谷原创O2优化动态规划优化洛谷月赛

「IXOI R2」想不出来

Background

As you can see, the problem setter cannot think of a problem name again.

[Big Head].jpg

Problem Description

Given a sequence xx of length nn.

You have a sequence pp of length nn, initially i[1,n],pi=1\forall i\in [1,n],p_i=1.

Define one operation as: choose i[1,n]i\in[1,n], and move the numbers at positions i1i-1 and i+1i+1 in the sequence to position ii.

Formally, each operation can be seen as setting:

  • pipi+pi1+pi+1p_i\leftarrow p_i+p_{i-1}+p_{i+1};
  • pi10p_{i-1}\leftarrow 0;
  • pi+10p_{i+1}\leftarrow 0.

In particular, if position i1i-1 or i+1i+1 does not exist, then no operation is performed at position i1i-1 or i+1i+1.

We call a sequence pp' stupid if and only if it can be generated from the initial sequence pp by performing the operation any number of times.

We call two sequences a,ba,b essentially different if and only if i[1,n],aibi\exist i\in [1,n],a_i\neq b_i.

Define the weight of a sequence pp' as:

i=1nxipi\prod_{i=1}^n x_i^{p'_i}

Now, compute the sum of weights of all essentially different stupid sequences pp', and output the result modulo 109+710^9+7.

Here, it is considered that 00=10^0=1.

Input Format

The input has two lines. The first line contains an integer nn. The second line contains an array xx of length nn.

Output Format

Output one integer, representing the sum of weights of all essentially different stupid sequences pp', modulo 109+710^9+7.

6
2 3 1 5 6 6
648718
5
17 43 2 6 7
207004448

Hint

This problem uses bundled testdata.

Subtask nn\le Special Property Score
11 88 None 55
22 500500 4040
33 80008000 xi=1x_i=1 1010
44 xi{0,1}x_i\in \{0,1\} 2020
55 None 2525

For all data, it is guaranteed that:

It is guaranteed that 0xi<109+70\le x_i< 10^9+7.

Translated by ChatGPT 5