Given a set U of N integers the task is decide if it is possible to divide them into K non-empty groups such that the sum of elements in each of the Kgroups is equal.
Explaination
Denote the total sum S of all integers in U, and the required sum M=S/K of each of the K groups. If M is not an integer, then there’s no solution.
DP on each possible subset X\subseteq U, dp[X]=1 iff X can be partitioned into k groups each sums to M, and a last (possibly empty) group sums to r \in [0,M-1], assume sum of integers in X is S_x=kM+r.
3. dp[\emptyset]=1,
3. Initially dp[X]=0; For each integer x\in X, let Y=X\setminus \{x\}, if x\le r(or x\le M if r=0) and dp[Y]=1, then dp[X]=1.
4. dp gives the final answer.
Use a N-bit bitmask to represent and iterate subsets.