#P10914. [蓝桥杯 2024 国 B] 跳石头

[蓝桥杯 2024 国 B] 跳石头

Problem Description

Xiaoming is playing a small jumping-stones game with his friends. There are nn stones in a row, numbered from 11 to nn. The ii-th stone has a positive integer weight value cic_i written on it.

If at some moment Xiaoming is on stone jj, then he may choose to jump to stone j+cjj + c_j (provided that j+cjnj + c_j \le n), or jump to stone 2j2j (provided that 2jn2j \le n). If there is no stone he can jump to, the game ends.

Suppose Xiaoming chooses to start jumping from stone xx. If a stone may be visited by Xiaoming (where “visited” means that there exists some moment when Xiaoming is on this stone), then the weight value of this stone is included in the score set SxS_x. Then Xiaoming’s score when starting from stone xx is Sx|S_x|.

For example, if Xiaoming starts from stone xx and the weight values on all stones that may be visited are 5,3,5,2,35, 3, 5, 2, 3, then Sx={5,3,2}S_x = \{5, 3, 2\} and the score is Sx=3|S_x| = 3. Xiaoming may choose any stone to start from. Please compute the maximum score Xiaoming can obtain.

Input Format

The input has 22 lines.

The first line contains a positive integer nn.

The second line contains nn positive integers c1,c2,,cnc_1, c_2, \cdots, c_n, separated by spaces.

Output Format

The output has 11 line, containing one integer, which is the answer.

5
4 3 5 2 1
4

Hint

Sample Explanation

Starting from the first stone gives the maximum score. The possible paths are as follows:

  1. Stone 11 \to stone 55: choose to jump from stone 11 to stone 1+c1=51 + c_1 = 5.
  2. Stone 11 \to stone 22 \to stone 55: first choose to jump from stone 11 to stone 2×1=22 \times 1 = 2, then choose to jump from stone 22 to stone 2+c2=52 + c_2 = 5.
  3. Stone 11 \to stone 22 \to stone 44: first choose to jump from stone 11 to stone 2×1=22 \times 1 = 2, then choose to jump from stone 22 to stone 2×2=42 \times 2 = 4.

Therefore, the set of weight values of all stones that may be visited is S1={c1,c2,c4,c5}={4,3,2,1}S_1 = \{c_1, c_2, c_4, c_5\} = \{4, 3, 2, 1\}, and the score is S1=4|S_1| = 4.

Constraints

For 20%20\% of the testdata, it is guaranteed that n20n \le 20.
For 100%100\% of the testdata, it is guaranteed that n40000n \le 40000 and cinc_i \le n.

Translated by ChatGPT 5