Merge branch 'haiker2011-patch-interview' of https://github.com/haiker2011/Interview-Notebook into haiker2011-patch-interview
This commit is contained in:
commit
63786dc9d9
@ -1241,6 +1241,20 @@ public int integerBreak(int n) {
|
||||
```
|
||||
|
||||
|
||||
### 动态规划
|
||||
|
||||
```java
|
||||
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(j * (i - j), dp[j] * (i - j)));
|
||||
return dp[n];
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
# 参考文献
|
||||
|
||||
- 何海涛. 剑指 Offer[M]. 电子工业出版社, 2012.
|
||||
|
Loading…
x
Reference in New Issue
Block a user