There are a total of n questions available. The objective is to find and generate as many quizzes as possible with the following conditions.
INPUT :
- Each question belongs to any one of the 3 categories. namely
JAVA
,PYTHON
andMYSQL
- Each question belongs to any one of the 2 difficulty level.
EASY
andDIFFICULT
RULES THAT A QUIZ MUST SATISFY :
There must be at least 1 question from each category(java | python | mysql).
at least 2 questions from each difficulty level.
A quiz must contain exactly 5 questions. (Lets call this number K)
A question once added to a quiz, can not repeat in any other quiz.
I've tried the naive way with following strategy:
Form n/k groups.
If there are 15 questions and k=4 , we can form at most 15/4=3 quizzes (groups).
For each group, iterate through questions and add them to that group if it satisfies the conditions.
If a question is added, decrement the quiz's difficulty requirement and category requirement
Once we have groups with minimum conditions satisfied, iterate through the leftover questions and add them to quizzes so that the quiz will contain K questions.
The problem with this is, It only works if the input questions are in a specific favorable order. I ran the program with input questions randomly shuffled. I got different outputs. (I can share the code if required)
So, what I understood is, the above solution is not reliable. We have to exhaustively check for all combinations of questions. This seemed to be very similar to Minimum coins change problem.
This is different from MCC
in following ways
- There are only limited supply of coins. {1,1,2,2,2,3,4,5}
- We don't need number of coins but group of coins that satisfy some conditions.
- Maximize. not minimize.
- Maximize the number of groups(not coins) that satisfy given conditions.
I know there exists a DP solution for this. I spent a couple of days trying to get the reccurence relation. But I could not arrive at one.
How can I solve this using DP? How can I derive the recurrence relation for this problem? Please start with recursive solution if possible