Codeforces - E. K Balanced Teams
Problem Link Problem Summary There are N students that each have a skill rating a_i. You need to group them (not necessarily all) into at least one and at most K non-empty groups, but the range of skill ratings of the students in a group should not exceed 5. Find the number of ways the students may be divided into groups. Algorithm Used Knapsack DP, Sorting Editorial First, sort the skill ratings in ascending order - this will make find the answer easier later on. Let's say we have to find the answer to following problem: make j groups and only choosing from the first i students. To find the answer to this subproblem, we can use the following subproblems: Don't include the ith student in the jth group. Include the ith student in the jth group. If we don't include the ith student in the jth group, then the answer to this subproblem is simply the answer for grouping i-1students in j group. But if we include the ith student in the jth group, then we find the number of stud...