Cut Rope
Given a rope length n, find the max product between possible rope cuts.
There need to be at least one cut.
Solution: DP with value array
Base Case: 0 and 1 length cannot be cut, thus = 0
Inductive rule:
Slowly grow the rope to length n
At each length of rope, check every possible cut.
Case 1: No cut is best cut
Case 2: Cut here into two segments
Case 3: Cut m times up to here, check for n with prev steps
Update max amongst all three cases.
Update max amongst all cuts at current length
Return bestCuts[n]
Implementation:
TC: O(N^2) double for loop through 1 -> N
SC: O(N) memoize array
Last updated
Was this helpful?