Your code is based the grouping strategy, but exists some unnecessary compution, e.g. num = 17, 33, etc. Relatively speaking, I think the DP solution is more efficiency and easier to understand and implement.