1 2 3 4 5 6 7 8 9 10 11 12 13
| class Solution { public int cuttingRope(int n) { int[] dp = new int[n + 1]; dp[1] = 1; dp[2] = 1; for (int i = 3; i <= n; i++) { for (int j = 1; j < i; j++) { dp[i] = Math.max(dp[i], j * Math.max(dp[i - j], i - j)); } } return dp[n]; } }
|