Last active
May 27, 2018 04:46
-
-
Save thmain/ec2f8018ec82d6dbc3c9b625ee4d9654 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MaximumProductCutting { | |
public int maxProdutRecursion(int n) { | |
// base case | |
if (n == 0 || n == 1) { | |
return 0; | |
} | |
// make all possible cuts and get the maximum | |
int max = 0; | |
for (int i = 1; i < n; i++) { | |
// Either this cut will produce the max product OR | |
// we need to make further cuts | |
max = Math.max(max, | |
Math.max(i * (n - i), i * maxProdutRecursion(n - i))); | |
} | |
//return the max of all | |
return max; | |
} | |
public static void main(String[] args) throws java.lang.Exception { | |
MaximumProductCutting i = new MaximumProductCutting(); | |
System.out.println("Maximum Product: "+i.maxProdutRecursion(10)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment