题目链接:https://leetcode-cn.com/problems/integer-break/submissions/
题目描述:
题解:
参考链接:整数拆分官方题解
class Solution {
public:
int integerBreak(int n) {
//dp[i]: 数字i拆分后得到的最大乘积
vector<int> dp(n + 1, 0);
//0,1不可差分为至少两个正整数的和
dp[0] = 0;
dp[1] = 0;
for(int i = 2; i <= n; i++)
{
int curMax = 0;
for(int j = 1; j < i ; j++)
{
curMax =max(curMax, max(j * (i - j), j * dp[i - j]));
}
dp[i] = curMax;
}
return dp[n];
}
};