#P5417. [CTSC2016] 萨菲克斯·阿瑞
[CTSC2016] 萨菲克斯·阿瑞
Description
Xiao P came to the contest site of NOIP2044. He found that the second problem was like this: given a string of length , formed by at most different characters, where the number of occurrences of the -th character is at most , ask what the suffix array of this string is.
Clever Xiao P thought of a new problem and hopes you can help solve it: under the constraints given in the problem, how many different answers can there be. That is, among all strings of length formed by characters, where the number of occurrences of the -th character is at most , how many different suffix arrays are there in total.
Since the answer is very large, you only need to output the answer modulo .
For a string , let denote the substring from position to the end. The suffix array is a permutation of to , satisfying $\mathrm{suf}(p_1) < \mathrm{suf}(p_2) < \dots < \mathrm{suf}(p_n)$. For two strings and , let be the first position such that . Then the string with the smaller one among and is smaller. If such does not exist, then the shorter string is smaller.
For the ordering between characters, we define that the -st character is the smallest, the -nd character is the next smallest, and so on.
Input Format
The first line contains two positive integers , meaning the length of the string is , and there are kinds of characters.
The next line contains non-negative integers , meaning the maximum number of occurrences of each character. It is guaranteed that and .
Output Format
Output one line containing a positive integer, representing the answer.
3 2
2 2
5
10 5
2 3 4 3 2
1003811
Hint
Explanation of Sample 1
Let be the first kind of character and be the second kind of character. Then there are possible strings: . Their suffix arrays are
So there are different results.
Constraints
For the first of the test points, .
Another of the test points: .
Another of the test points: . Among them, for of the test points , for of the test points , and for of the test points .
Another of the test points: .
Another of the test points: .
Another of the test points: .
Translated by ChatGPT 5
京公网安备 11011102002149号