求一个PHP商品装箱最小化的算法,贪婪算法?
现有php订单商品列表数组如下:
$goods = [
20200702024 => [ "name" => "LP-雨伞", // 商品名称
"bar_code" => "20200702024",// 条形码
"quantity" => "3", // 数量
"scan_mode" => "5", // 发货模式
"volume" => "15.6", // 体积
],
6970328080043 => [
"name" => "压缩面膜", "bar_code" => "6970328080043",
"quantity" => "1",
"scan_mode" => "5",
"volume" => "23",
],
6922994301816 => [
"name" => "洁面巾", "bar_code" => "6922994301816",
"quantity" => "5",
"scan_mode" => "3",
"volume" => "20",
],
6922994300765 => [ "name" => "鲜藻精华面膜",
"bar_code" => "6922994300765",
"quantity" => "11",
"scan_mode" => "4",
"volume" => "36",
],
6922994300192 => [
"name" => "甘菊花露水",
"bar_code" => "6922994300192",
"quantity" => "8",
"scan_mode" => "1",
"volume" => "65",
],
];
现有包裹箱子体积固定为300,如何拆分订单商品。
拆分包裹条件:
1、最小化拆分包裹,不能浪费箱子
2、每个商品的体积是单个的,总体积= 商品数量 X 单个体积
3、商品可以随意搭配装箱,只要满足最后的条件,箱子最小化,不浪费一个箱子
4、比如:有些商品装3个就满了,但是它有8个,也要拆开放下一个箱子
5、使用PHP语言,这个算法应该如何写?
回答:
无解。因为不知道长宽高。
以上是 求一个PHP商品装箱最小化的算法,贪婪算法? 的全部内容, 来源链接: utcz.com/a/167134.html