Bunch of Paper
Time limit2sMemory limit512 MB
Count non-decreasing sequences that pick one value from each of N sorted lists of K integers, modulo 1e9+7.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Sorting, Binary search, Combinatorics
- Solved
- No attempts yet
Problem
There are sheets of paper, numbered with the consecutive integers from to . Each sheet has integers written on it, so the -th sheet contains .
Choose one integer from each sheet to form the sequence , where the integer chosen from the -th sheet becomes . There are ways to form such a sequence. How many of them are non-decreasing? A sequence is non-decreasing if for every .
The answer may be large, so print it modulo .
Input
The first line contains two integers and (, ). The -th of the following lines contains integers ().
Output
Print the number of non-decreasing sequences modulo .