Last active
May 27, 2018 05:09
-
-
Save thmain/c7c714c7332dc43d7e74d7b3f2a4ca26 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 void maxProductCutting(int n) { | |
int[] MPC = new int[n + 1]; | |
MPC[1] = 1; | |
for (int i = 2; i < n + 1; i++) { | |
int mp = Integer.MIN_VALUE; | |
for (int j = 1; j < i; j++) { | |
mp = Math.max(mp, Math.max(j * MPC[i - j], j * (i - j))); | |
} | |
MPC[i] = mp; | |
} | |
System.out.println("Dynamic Programming: Maximum product cutting in " | |
+ n + " is: " + MPC[n]); | |
} | |
public static void main(String[] args) throws java.lang.Exception { | |
MaximumProductCutting i = new MaximumProductCutting(); | |
i.maxProductCutting(10); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment