P r o b l e m \mathrm{Problem} Problem
There are n n n students in a class working on group projects. The students will divide into groups (some students may be in groups alone), work on their independent pieces, and then discuss the results together. It takes the i i i -th student a i a_{i} ai minutes to finish his/her independent piece.
If students work at different paces, it can be frustrating for the faster students and stressful for the slower ones. In particular, the imbalance of a group is defined as the maximum a i a_{i} ai in the group minus the minimum a i a_{i} ai in the group. Note that a group containing a single student has an imbalance of 0 0 0 . How many ways are there for the students to divide into groups so that the total imbalance of all groups is at most k k k ?
Two divisions are considered distinct if there exists a pair of students who work in the same group in one division but different groups in the other.
S o l u t i o n \mathrm{Solution} Solution
这道题,我们首先想到排序,对于一个数字我们可以分成 4 4 4 类:贡献为 − 1 -1 −1 的最小值,贡献为 1 1 1 的最大值,贡献为 0 0 0 的中间值或单独一组。
我们我们设 f ( i , j , k ) f(i,j,k) f(i,j,k) 表示前 i i i 个数,有 j j j 组数需要求出最大值,和为 k k k 的方案。
- 当前数为最小值时,贡献为 f