题目链接:https://leetcode.cn/problems/integer-break/
题目如下:
class Solution {
public:
int integerBreak(int n) {
vector<int> dp(n+1,0);
dp[2]=1;
for(int i=3;i<=n;i++){
for(int j=1;j<i-1;j++){
//从1遍历j,比较(i - j) * j和dp[i - j] * j 取最大的
dp[i]=max( dp[i], max( (i-j)*j, dp[i-j]*j ) );
}
}
return dp[n];
}
};