https://leetcode.com/problems/integer-break/description/
解题思路:
- 双层循环
- dp[i] = Math.max(dp[i], Math.max(dp[j], j) * Math.max(dp[i - j], i - j));
class Solution {
public int integerBreak(int n) {
int[] dp = new int[n + 1];
dp[1] = 1;
for(int i = 2; i <= n; i++){
for(int j = 1; j < i; j++){
dp[i] = Math.max(dp[i], Math.max(dp[j], j)*Math.max(dp[i - j], i - j));
}
}
return dp[n];
}
}






网友评论