Just a bit sorted
Time limit3sMemory limit256 MB
For each query bound K, count length-N lists with values 1 to K where each value above 1 has its predecessor before its last occurrence.
- Level
Hard8 of 10
- Topics
- Combinatorics, Dynamic programming, Math
- Solved
- No attempts yet
Problem
Jurgen Guntherswarchzhaffenstrassen is known for his guitar playing and for the harsh way he teaches his students. Most people miss one more thing about him. He also likes numbers.
Jurgen has been studying sorted lists lately, and he got bored. Sorted lists are too predictable and there are too few of them, so he changed the rule a little.
Take a list of positive integers. The elements do not have to be distinct. Jurgen calls just a bit sorted if for every integer that occurs in , the value occurs at least once before the last occurrence of in . For example:
- is just a bit sorted, because a 1 stands before the last 2 and a 2 stands before the last 3.
- is not just a bit sorted, because every 1 stands after the last 2.
- is not just a bit sorted, because no 2 stands before the last 3. This list has no 2 at all.
Jurgen wants to know how many different just a bit sorted lists of positive integers not greater than exist. Two lists are different if they differ in at least one position. Count them for him.
Input
The first line contains the length of the lists and the number of queries (, ). The second line contains the integers . The lists counted in the -th query contain no value greater than ().
Output
Print one line with integers separated by single spaces. The -th integer is the number of different just a bit sorted lists of positive integers not greater than . This number can be very large, so print it modulo .