Update IntegerBreak.cpp
This commit is contained in:
parent
c62c3837de
commit
8a1623ecf3
@ -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];
|
||||
}
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user