luogu#P4798. [CEOI 2015] 卡尔文球锦标赛 (Day1)

    ID: 3824 远端评测题 1000ms 63MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>动态规划 DP2015CEOI(中欧)数位 DP

[CEOI 2015] 卡尔文球锦标赛 (Day1)

Problem Description

Translated from CEOI2015 Day1 T2 “Calvinball championship”.

A Calvinball match has nn players participating, numbered 1n1 \dots n, and they are divided into several non-empty teams. We define the order of teams by sorting them according to the smallest player number in each team, and then numbering the teams with consecutive integers starting from 11.

For example, suppose player 11 forms a team alone; players 2,3,2, 3, and 55 form a team; and players 44 and 66 form a team.

>  1\ \texttt{1}
>  2 3 5\ \texttt{2 3 5}
>  4 6\ \texttt{4 6}

Then player 11’s team is team 11, player 22’s team is team 22, and player 44’s team is team 33.

>  1|1\ \texttt{1|1}
>  2|2 3 5\ \texttt{2|2 3 5}
>  3|4 6\ \texttt{3|4 6}

Each day, everyone will choose a different team partition. When recording, we can omit the player numbers and only record the sequence of team numbers that each position belongs to (in the above example, 1 2 2 3 2 3), because the players are the same every day. The championship ends when all possible choices have been used.

Since there are too many choices, indecisive people find it hard to handle. This year, we decide to choose the partitions according to the lexicographical order of the recorded sequences. Therefore, on the first day, everyone is in one team: 1 1 1 1 1 1; on the second day, everyone opposes player 66: 1 1 1 1 1 2; … on the last day, everyone is in their own team: 1 2 3 4 5 6.

Given a recorded team sequence, compute on which future day this record will be used. Output this number modulo 1 000 0071\ 000\ 007.

Input Format

The first line contains a positive integer n(1n10 000)n(1 \leq n \leq 10\ 000).

The second line contains nn positive integers separated by spaces, representing the team record given in the task.

Output Format

Output a positive integer: the day on which the given team record will be used, modulo 1 000 0071\ 000\ 007. The first day is numbered 11.

3
1 2 2
4

Hint

Please note that for a three-player match, the possible choices are 1 1 1, 1 1 2, 1 2 1, 1 2 2, and 1 2 3.

Constraints and Hints

Test case 131-3 454-5 676-7 8108-10
nn \le 1414 100100 1 0001\ 000 10 00010\ 000

Translated by ChatGPT 5