Given N students and a total of M sets of question paper where M ≤ N. All the M sets are different and every sets is available in sufficient quantity. All the students are sitting in a single row. The task is to find the number of ways to distribute the question paper so that if any M consecutive students are selected then each student has a unique question paper set. The answer could be large, so print the answer modulo 109 + 7. Example:
Input: N = 2, M = 2 Output: 2 (A, B) and (B, A) are the only possible ways. Input: N = 15, M = 4 Output: 24
Approach: It can be observed that the number of ways are independent of N and only depend on M. First M students can be given M sets and then the same pattern can be repeated. The number of ways to distribute the question paper in this way is M!. For example,
N = 6, M = 3 A, B, C, A, B, C A, C, B, A, C, B B, C, A, B, C, A B, A, C, B, A, C C, A, B, C, A, B C, B, A, C, B, A
Below is the implementation of the above approach:
Please Login to comment...