Update IntegerBreak.cpp

This commit is contained in:
TaoWei 2019-05-14 09:36:20 +08:00 committed by Hao Chen
parent c62c3837de
commit 8a1623ecf3

View File

@ -44,3 +44,16 @@ public:
}
};
// DP
class Solution {
public:
int integerBreak(int n) {
vector<int> dp(n+1,1);
for(int i=2;i<=n;i++){
for(int j=1;j<=i/2;j++){
dp[i] = max(dp[i],max(dp[j],j)*max(dp[i-j],i-j));
}
}
return dp[n];
}
};