Share the joy
https://leetcode.com/problems/integer-break/
Given a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Return the maximum product you can get.
For example, given n = 2, return 1 (2 = 1 + 1); given n = 10, return 36 (10 = 3 + 3 + 4).
Solution. This is a classical dp problem.
For n, split n to left and right part. So, left part has i, right part has n – i. Then we calculate leftMax and rightMax:
leftMax = max(i, dp[i])
rightMax = max(n – i, dp[n – i])
so, dp[n] = max(leftMax * rightMax)
check my code on github: java, python