The problem of steel bar cutting in dynamic planning

Source: Internet
Author: User

/* * 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.