/* * Steel strip cutting scheme bottom up */public class Cutrodbottom2up {//Bar Price table Private final int[] price={1,5,8,9,10,17,17,20,24,30};p ublic static void Main (string[] args) {new Cutrodbottom2up (). Start (); private void Start () {for (int i=1;i<=10;i++) {//print an optimal scheme printcutrodsolution (i);}} Private cutrodsolution Bottomupcutrod (int n) {cutrodsolution crsl = new Cutrodsolution (price.length+1); crsl.r[0] = 0;for (int j=1;j<=n;j++) {//Because the steel bar price is non-negative, so-1 can be regarded as-ooint q=-1;for (int i=1;i<=j;i++) {if (Q < price[i-1]+crsl.r[j-i]) {//Storage optimal return value q = price[i-1]+ crsl.r[j-i];//Storage Optimal cutting method (first cut length) crsl.s[j] = i;}} CRSL.R[J] = q;} return CRSL;} Print output steel strip length n complete cut scheme private void printcutrodsolution (int n) {cutrodsolution sl = Bottomupcutrod (n); System.out.print ("+n+" the optimal yield of the steel bar is: "+sl.r[n]+"); System.out.print ("cutting scheme:"), while (n > 0) {System.out.print (sl.s[n]+ ""); n = n-sl.s[n];} System.out.println ();} Internal class storage Optimal cutting scheme information private static class Cutrodsolution {//Storage optimal yield value array r[0..n]int[] r = null;//storage optimal cut scheme array s[0..n]int[] s = null; Public Cutrodsolution (inT capacity) {r = new Int[capacity];s = new int[capacity];}}
The problem of steel bar cutting in dynamic planning