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
- Count of ways to distribute N items among 3 people with one person receiving maximum
- Distribute N candies among K people
- Minimum and maximum number of N chocolates after distribution among K students
- Count ways to distribute exactly one coin to each worker
- Count the number of ways to give ranks for N students such that same ranks are possible
- Minimum number of mails required to distribute all the questions
- Distribute candies in a Binary Tree
- Find ways to arrange K green balls among N balls such that exactly i moves is needed to collect all K green balls
- Why is programming important for first year or school students?
- Maximum students to pass after giving bonus to everybody and not exceeding 100 marks
- Find Non-overlapping intervals among a given set of intervals
- Find position of the given number among the numbers made of 4 and 7
- Paper Cut into Minimum Number of Squares
- Number of wins for each player in a series of Rock-Paper-Scissor game
- Sum of bit differences among all pairs
- Repeated subtraction among two numbers
- Find maximum among x^(y^2) or y^(x^2) where x and y are given
- Position of n among the numbers made of 2, 3, 5 & 7
- Print N lines of 4 numbers such that every pair among 4 numbers has a GCD K
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.