Consider the following variant of the Rod Cutting problem As
Solution
There can be n-1 cuts can be made in the rod of length n, so there are 2n-1 ways to cut the rod.
So for every length we have 2 options either we cut it or not. we will consider both the options and choose the optimal out of it
Code:
public static int profit(int[] value, int length) {
if (length <= 0)
return 0;
// either we will cut it or don\'t cut it
int max = -1;
for(int i=0;i<length;i++)
max = Math.max(max, value[i] + profit(value, length i+1)));
return max;
}
Time Complexity: O(2n-1)
But this time complexity is very high since we are solving many sub problems repeatedly.

