Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.IOException;
- class type {
- static int cut_rod(int p[], int n) {
- if (n == 0)
- return 0;
- int q = -1;
- for (int i = 1; i <= n; i++)
- q = Math.max(q, p[i] + cut_rod(p, n - i));
- return q;
- }
- public static void main(String args[]) throws NumberFormatException,
- IOException {
- int[] p = {0,1,5,8,9,10,17,17,20,24,30};
- int r = 4;
- System.out.println(cut_rod(p,r));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement