/**
Problem Statement: Given a rod of length n inches and an array of prices that contains prices of all pieces of size smaller than n.
Determine the maximum value obtainable by cutting up the rod and selling the pieces.

Time Complexity: O(n^2)
Space Complexity: O(n)
 */

public class RodCutting {

    public static int cutRod(int[] price) {
        int n = price.length;
        int[] best_price = new int[n+1];
        for (int i = 1;i < best_price.length;i++)
            best_price[i] = price[i-1];
        for (int i = 1; i <= n; i++)
            for (int j = i; j < n+1; j++)
                best_price[j] = Math.max(best_price[j], best_price[j-i] + best_price[i]);
        return best_price[n];
    }

    public static void main(String[] args) {
        int[] price = new int[] {10, 52, 84, 93, 101, 17, 117, 20};
        System.out.println("Maximum Obtainable Value is " + cutRod(price));
    }
}

@@ -1,8 +1,7 @@
 /*
-*
 %0A
+
 Prob
@@ -265,12 +265,11 @@
 (n)%0A
- 
 */%0A
+
 %0Apub
@@ -411,62 +411,8 @@
 1%5D;%0A
-        for (int i = 1;i %3C best_price.length;i++)%0A    
     
@@ -430,23 +430,14 @@
 ice%5B
-i
+0
 %5D = 
-price%5Bi-1%5D
+0
 ;%0A  
@@ -470,16 +470,60 @@
  n; i++)
+ %7B%0A            int tmax = Integer.MIN_VALUE;
 %0A       
@@ -544,18 +544,16 @@
 j = 
-i
+0
 ; j %3C 
-n+1
+i
 ; j+
@@ -571,29 +571,20 @@
         
-best_price%5Bj%5D
+tmax
  = Math.
@@ -591,21 +591,22 @@
 max(
-best_
+tmax, 
 price%5Bj%5D
 , be
@@ -601,17 +601,18 @@
 price%5Bj%5D
-,
+ +
  best_pr
@@ -619,30 +619,60 @@
 ice%5B
-j-i%5D + best_price%5Bi%5D);
+i-j-1%5D);%0A            best_price%5Bi%5D = tmax;%0A        %7D
 %0A   

Update RodCutting.java to GeeksForGeeks algo (#379)