(int price[], int n)
| 14 | System.out.println("Maximum Obtainable Value is " + rodcut(arr, size)); |
| 15 | } |
| 16 | static int rodcut(int price[], int n) |
| 17 | { |
| 18 | if (n <= 0) |
| 19 | return 0; |
| 20 | int max = Integer.MIN_VALUE; |
| 21 | |
| 22 | for (int i = 0; i < n; i++) |
| 23 | max = Math.max(max, price[i] + rodcut(price, n - i - 1)); |
| 24 | |
| 25 | return max; |
| 26 | } |
| 27 | } |
| 28 | |
| 29 |