rod cutting

Posted Wujunde

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了rod cutting相关的知识,希望对你有一定的参考价值。

for a rod of length i the price of it si pi,to cut the rod to earn more money

package dynamic_programming;

public class rod_cutting {
    int [] r;
    public int[] BTU_rod_cutting(int[] p,int n)
    {
          r = new int[n];  //r[n] is the most money of the //length n 
        int[] s = new int[n];
        int q;
        r[0] = 0;
        for(int j = 0;j <= n-1;j++){ //all the amount
            q = -1;
            for(int i = 0;i<=j;j++){//divide
                if(q < p[i] + r[j-i]){
                q = p[i] + r[j-i];
                s[j] = i;    //record j rods how to divide
                }
                
            }
            r[j] = q;  //every time memory it
            
        }
        return s;
    }
    
    public void print(int[] p,int n){
        int[] a = BTU_rod_cutting(p,n);
        while(n>=0){
             System.out.println(a[n-1]+"");
             n = n - a[n-1];
        }
    }
}

 

以上是关于rod cutting的主要内容,如果未能解决你的问题,请参考以下文章

Rod cutting - Using Dynamic Programming

非常简短的片段:PHP word cut

Final Cut Pro X中的音视频片段如何自由拖动?

shell选取部分内容

河内五钉塔

Linux下cut命令使用