package com.xisc.pm.infra.util;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

import com.xisc.pm.app.service.autoboard.dto.PmAutoBoardExecResult;
import com.xisc.pm.app.service.autoboard.dto.PmContBoardParam;

/**
 * 组板工具类
 * 
 * @author jun.zeng
 *
 */
public class BoardUtils {

    /**
     * 从集合中选择M个数，使其和最接近K 01背包实现
     */
    public static void zeroOnePack(List<PmContBoardParam> orderList, BigDecimal sum , PmAutoBoardExecResult execResult) {
//        Map<String , PmContBoardParam> orderMap = 
        for (PmContBoardParam pmContBoardParam : orderList) {
            BigDecimal qty = execResult.calcRemainingPdQty(pmContBoardParam);
        }
    }
    
    /**
     * len 表示其价值
     * @param lens
     * @param sum
     */
    public static void zeroOnePack2(int[] lens, int sum) {
        
        int f[][] = new int [lens.length+1][sum];
        
        int w[] =  new int[lens.length];
        for (int i = 1 ; i < lens.length ;i++) {
            if(lens[i] / 100 != 0) {
                w[i] = (lens[i] / 100) + 1;
            } else {
                w[i] = (lens[i] / 100);
            }
        }
        
        for(int i = 1 ; i < lens.length ; i++) {
            for(int j = sum-1 ; j >= w[i] ; j--) {
                f[i][j] = max(f[i-1][j] , f[i-1][j-w[i]] + lens[i]);
            }
        }
        System.out.println(f[lens.length-1][sum-1]);
        int j = sum-1;
        for(int i = lens.length -1 ; i >= 1 ; i-- ) {
            if(f[i][j] != f[i-1][j]) {
                j = j - w[i] ;
                System.out.println(i);
            }
        }
    }

    public static void zeroOnePack(int[] lens, int sum) {
        int k = 0;
        int []result = new int[sum];
        for(int i = 1 ; i < lens.length ; i++) {
            for(int j = sum-1 ; j >= lens[i] ; j--) {
                result[j] = max(result[j] , result[j - lens[i]] + lens[i]);
                k++;
            }
        }
        System.out.println(k);
        System.out.println(result[sum-1]);
    }
    
    public static void main(String[] args) {
        
        int []len = new int[11];
        len[0] = 0;
        len[1] = 17500 ;
        len[2] = 12500 ;
        len[3] = 12500 ;
        len[4] = 16500 ;
        len[5] = 12500 ;
        len[6] = 16500 ;
        len[7] = 12000 ;
        len[8] = 12000 ;
        len[9] = 10500 ;
        len[10] = 13500 ;
        zeroOnePack2(len, 650);
//        zeroOnePack(len, 65000);
    }

    public static int max(int a , int b) {
        if(a > b) {
            return a;
        } else {
            return b ;
        }
    }
}
