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.
Input: N = 2, M = 2
(A, B) and (B, A) are the only possible ways.
Input: N = 15, M = 4
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:
- Count ways to distribute m items among n people
- Minimum number of mails required to distribute all the questions
- Minimum and maximum number of N chocolates after distribution among K students
- Distribute N candies among K people
- Distribute candies in a Binary Tree
- Paper Cut into Minimum Number of Squares
- Number of ways to split a binary number such that every part is divisible by 2
- Number of ways to calculate a target number using only array elements
- Find the number of ways to divide number into four parts such that a = c and b = d
- Count number of ways to divide a number in 4 parts
- Number of wins for each player in a series of Rock-Paper-Scissor game
- Number of ways to choose a pair containing an even and an odd number from 1 to N
- Number of ways to get a given sum with n number of m-faced dices
- Count number of ways to get Odd Sum
- Why is programming important for first year or school students?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.