Skip to content

Instantly share code, notes, and snippets.

@thmain
Last active May 27, 2018 05:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thmain/c7c714c7332dc43d7e74d7b3f2a4ca26 to your computer and use it in GitHub Desktop.
Save thmain/c7c714c7332dc43d7e74d7b3f2a4ca26 to your computer and use it in GitHub Desktop.
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