Dynamic Programming21 sections · 916 units
Open in Course

Lessons from Partition

summary

Three things to remember from this problem:

1.1. Partition problems often hide subset sum. If you need two groups with some property, check if one group having that property implies the other does too.

2.2. Boolean DP uses OR instead of max/min. The formula dp[s]=dp[s] OR dp[snum]dp[s] = dp[s] \text{ OR } dp[s-num] is simpler than value improvement.

3.3. Early exit conditions matter. Checking if the sum is odd saves you from running unnecessary DP.