求一个省料算法。多种尺寸和数量、多种材料尺寸

多种尺寸,多种原材料,计算最优的结果


//    import java.util.HashMap;
//    import java.util.Map;
    public static void main(String[] args) {
        /* 需要裁剪的尺寸大小 及数量 */
        Map<Integer,Integer> standard = new HashMap<>();
        standard.put(1000,6);
        standard.put(1250,2);
        standard.put(1600,4);
        standard.put(1500,4);
        standard.put(900,6);
        /* 多种原材料的原材料尺寸大小 */
        Integer[] material = {1000,1500,2000,2500,3000};

        Map<Integer,Integer> data = Tool(standard,material);

        for(Map.Entry<Integer, Integer>obj : data.entrySet()){
            System.out.println(obj.getKey()+" 需要: "+ obj.getValue());
        }
    }

    /**
     * @param standard 需要裁剪的尺寸大小 及数量
     * @param material 多种原材料的原材料尺寸大小 供选择使用
     * @return
     */
    public static Map Tool(Map<Integer,Integer> standard,Integer[]material){

//        ...

        /* 结果输出 */
        Map<Integer,Integer> map = new HashMap<>();
        /* (原材料尺寸,数量) */
        map.put(material[0],5);
        map.put(material[1],2);
        map.put(material[2],0);
        return map;
    }

 

求最值,动态规划试试