Following on from the previous problem in Chapter 1, today we expand this problem to make it a little more complicated.

Where is the extension? Is before, two boxes if points in a single, then calculate the total number of single model, the model number of the two cases directly to the respective together to go, and now, if, in the two boxes containing the same model, assigned to the same list of words, can combine model, after the box to between heavy model, the total is the total number of single model.

Here is an example of the concept of model merging:

Box 1 below 10 model [1] = > ([0] = > 55766 e89a05caba74e09e05f3cada80e [1] = > 77 b5c09b6d5e1d3323ad0b7ff352aeaa [2] = > b0a3e7babe36a55cb2f13336577a96fd [3] => 46e902f68228c599a3c09f11e8a11dce [4] => 43f9e4663d50b618f6c658f1be53b113 [5] => d690a3f429eec0c41f11ad325d98e299 [6] => d9804f1ed77995d5689566795836e8cf [7] => 288becbe90890e297c905ef8195e2897 [8] => 75777 ef58fa286b124c51a17fa141aea [9] = > a473d5d14febc5e9f721257dcd664d5d) box 2 has the following seven model [2] = > ([0] = > 87415b41b663fbb5d78629d303bf53d0 [1] => 59d99b563381a33cfaa5c4ebaf8025a1 [2] => d690a3f429eec0c41f11ad325d98e299 [3] => 9a85df0bf0badae7fbfcca5d70165de4 [4] => 77b5c09b6d5e1d3323ad0b7ff352aeaa [5] => 5ffe4ee06c146d9f419cc5b14181accb [6] => 288becbe90890e297c905ef8195e2897 )Copy the code

Can see two suitcases, d690a3f429eec0c41f11ad325d98e299, 77 b5c09b6d5e1d3323ad0b7ff352aeaa, 288 becbe90890e297c905ef8195e2897, these three models have two cases, So when added together, the total number of models = 10 + 7-3 = 14, not 17.

Understand the concept, then to see the real problem: a batch of goods, there is more than one box, each box there are different models, now required to separate the shipment into N, every single can contain more than one box, but each box can only belong to a single, and the inside of the each single merger model number is not greater than 50 】, ask how points method can achieve the optimal solution? Compared to Chapter 1, this is just the difference between Merging model numbers and simply adding numbers, but there are many more points to consider.

Imagine if one box has exactly 50 sizes, the second box has 13 sizes, and the 13 sizes in the second box are all in the first box, according to the rules of question 2, the two boxes can be combined into one single, because the sizes are all the same. But according to the rule in question 1, you can only divide into 2 orders, so if 50 are full, 13 can only go into the second order.

This is not only, there are more complex: box 1 = “45 model box 2 =” 5 model box 3 = “10 model behind more boxes omitted…

Box 1 box 2 repeat model 2, box 1 box 3 repeat model 5. According to question 1: box 1, box 2 and 50 together, perfect one order. But according to question 2: box 1 box 2 is 48, box 1 box 3 is 50, obviously 1 and 3 are better together. And if there are many boxes in the back, for example, box 4 has model 8, which are included in 1 and 3, then 1,3 and 4 can be combined with one single. In short, the total number of [combined models] is not more than 50.

When you think about it, most people think about array_merge, array_unique and count, but that’s still a big problem. 30 plus 15 plus 10 is better than 30 plus 20 plus 5.

As for me, the algorithm is written, and it runs error-free. But to be honest, we didn’t get to the optimal solution. First send the code (PHP version), the solution idea is written in the code comments.

/***** AutoDistributeDec.php *****/ <? PHP /** * Class AutoDistributeDec {// $boxProsnoNum public $boxProsnoNum = []; $boxMergeProsnoNum public $boxMergeProsnoNum = []; $boxMergeProsnoMd5 public $boxMergeProsnoMd5 = []; $keyBoxs = []; $keyBoxs = []; Public $decToBox = []; Public $decToProsnoMd5 = []; $decToProsnoMd5 = []; Public $tmpMergeBox = []; public $tmpMergeBox = []; Public function handleOrderDetail($customsDetailArr){foreach ($customsDetailArr as $value){ $tmp['box_num'] = $value['box_num']; $tmp['prosno_md5'] = $value['prosno_md5']; $this->boxProsnoNum[$tmp['box_num']] = empty($this->boxProsnoNum[$tmp['box_num']]) ? 1 : ++$this->boxProsnoNum[$tmp['box_num']]; $this->boxMergeProsnoNum[$tmp['box_num']][$tmp['prosno_md5']] = 1; } foreach ($this->boxMergeProsnoNum as $k3 => $v3){ $this->boxMergeProsnoNum[$k3] = count($v3); foreach ($v3 as $k4 => $v4) { $this->boxMergeProsnoMd5[$k3][] = $k4; } } arsort($this->boxProsnoNum); arsort($this->boxMergeProsnoNum); } /** * Merge type group single * allows different boxes containing the same type of items to be merged, so that the total number of items in a single order can be greater than 50, but the total number of models in a single order can not be greater than 50 * Also, each box can only belong to one single, but a single can contain multiple boxes. * * Group single principle: * The box number in accordance with the box combined model number order, take the first box, and then take the last 1 complement, 2 boxes to re-merge, judge enough 50, enough to jump out * not enough to take the second to the bottom continue to fill, continue to merge to weight, until enough 50, on the combination of a single. * Loop to remove the first and last ones, and continue to do the same from the rest. Exit until the remaining array is empty or the remaining number cannot assemble enough to reach 50. * * Optimization point * dynamic planning. If the first head-to-tail combination is less than 50, it should not take the penultimate box combination, but should try to merge from the remaining combinable options in a cycle to get the possible optimal combination term * optimal combination term definition: Array_intersect ($a1,$a2); Public function getBestSplit(){$this->keyBoxs = array_keys($this->boxMergeProsnoNum); $this->decToBox = []; $allIndex = 0; While (count($this->keyBoxs) > 0) {$headIndex = 0; $tailIndex = count($this->keyBoxs)-2; $t = 0; $this->tmpMergeBox = []; List ($total, $t) = $this->getTwoBoxMerge($allIndex, $headIndex, $tailIndex, $t); While ($total < 50) {if ($t > 0) {$this->decToBox[$allIndex][] = $this->decToBox[$allIndex] = $this->decToBox[$allIndex] = $this->decToBox[$allIndex] = $this->decToBox[$allIndex] = $this->keyBoxs[$tailIndex]; array_pop($this->keyBoxs); $tailIndex = $tailIndex - 1; } $t = $t +1; list($total, $t) = $this->getTwoBoxMerge($allIndex, $headIndex, $tailIndex, $t); If ($this->keyBoxs) == 0){$this->keyBoxs; If ($total == 50) {$total == 50; If ($t > 0) {$this->decToBox[$this->keyBox][] = $this-> keybox [$this->keyBox]; Array_pop ($this->keyBoxs); $tailIndex = $tailIndex - 1; }} $allIndex = $allIndex; Foreach ($this->decToBox as $k1 => $v1){if(count($v1) == 0){unset($this->decToBox[$k1]);  } if(count($v1) == 1 && ($v1[0] == "" || $v1[0] == 0)){ unset($this->decToBox[$k1]); Foreach ($this->decToBox as $k3 => $v3){$this->decToProsnoMd5[$k3] = []; foreach ($v3 as $v4){ $this->decToProsnoMd5[$k3] = array_unique(array_merge($this->decToProsnoMd5[$k3],$this->boxMergeProsnoMd5[$v4])); } } print_r($this->decToProsnoMd5); die; ***/ return $this->decToBox; } /** * Determine if two boxes can be combined into a single, */ public function getTwoBoxMerge($allIndex, $headIndex, $tailIndex, $tailIndex) $t){ if($t == 0){ $this->tmpMergeBox = $this->boxMergeProsnoMd5[$this->keyBoxs[0]]; $this->decToBox[$allIndex][] = $this->keyBoxs[$headIndex]; Array_shift ($this->keyBoxs); Return [count($this-> keyBoxs[0]]), 0]; } $t = end($this->keyBoxs); $hBox = $this->keyBoxs[$headIndex]; $tBox = $this-> keybox [$this-> keybox]; If ($hBox == $tBox){$hBox == $tBox; If (is_array($this->boxMergeProsnoMd5[$tBox])){$this->tmpMergeBox = array_unique(array_merge($this->tmpMergeBox, $this->boxMergeProsnoMd5[$tBox])); } if(count($this-> tmpgeBox) > 50){$this->decToBox[$this-> tmpgebox][] = $hBox; $this->decToBox[$allIndex][] = $hBox; $this->decToBox[] = $hBox; } $this->keyBoxs = []; Return [999, $t]; } if(count($this->tmpMergeBox) == 0) { $this->tmpMergeBox = array_unique(array_merge($this->boxMergeProsnoMd5[$hBox], $this->boxMergeProsnoMd5[$tBox])); $this->tmpMergeBox = array_unique($this->tmpMergeBox, $this->tmpMergeBox, $this->tmpMergeBox) $this->boxMergeProsnoMd5[$tBox])); } return [count($this->tmpMergeBox), $t]; }}Copy the code
/*****  demo.php  *****/
<?php
include 'AutoDistributeDec.php';

$testDataStr = '[{"box_num":"1","prosno_md5":"55766e89a05caba74e09e05f3cada80e"},{"box_num":"1","prosno_md5":"77b5c09b6d5e1d3323ad0b7ff352aeaa"},{"box_num":"1","prosno_md5":"b0a3e7babe36a55cb2f13336577a96fd"},{"box_num":"1","prosno_md5":"46e902f68228c599a3c09f11e8a11dce"},{"box_num":"1","prosno_md5":"43f9e4663d50b618f6c658f1be53b113"},{"box_num":"1","prosno_md5":"d690a3f429eec0c41f11ad325d98e299"},{"box_num":"1","prosno_md5":"d9804f1ed77995d5689566795836e8cf"},{"box_num":"1","prosno_md5":"d9804f1ed77995d5689566795836e8cf"},{"box_num":"1","prosno_md5":"d690a3f429eec0c41f11ad325d98e299"},{"box_num":"1","prosno_md5":"d690a3f429eec0c41f11ad325d98e299"},{"box_num":"1","prosno_md5":"d690a3f429eec0c41f11ad325d98e299"},{"box_num":"1","prosno_md5":"d690a3f429eec0c41f11ad325d98e299"},{"box_num":"1","prosno_md5":"77b5c09b6d5e1d3323ad0b7ff352aeaa"},{"box_num":"1","prosno_md5":"288becbe90890e297c905ef8195e2897"},{"box_num":"1","prosno_md5":"75777ef58fa286b124c51a17fa141aea"},{"box_num":"1","prosno_md5":"a473d5d14febc5e9f721257dcd664d5d"},{"box_num":"1","prosno_md5":"bbb80c56253abc8d29ed0932ee28803b"},{"box_num":"1","prosno_md5":"a473d5d14febc5e9f721257dcd664d5d"},{"box_num":"1","prosno_md5":"288becbe90890e297c905ef8195e2897"},{"box_num":"1","prosno_md5":"6a0d77b6117be7ae467f901a524cbe5e"},{"box_num":"1","prosno_md5":"6a0d77b6117be7ae467f901a524cbe5e"},{"box_num":"1","prosno_md5":"6a0d77b6117be7ae467f901a524cbe5e"},{"box_num":"1","prosno_md5":"77a3de3b5cc3b50ab96beac63ba6d992"},{"box_num":"1","prosno_md5":"7a1bfb3f4aebb6f6c01750089f785f3c"},{"box_num":"1","prosno_md5":"89dccb2b7ae54dc9daa6fffc63618d2f"},{"box_num":"1","prosno_md5":"0d5f3e546451d4849861111e486657bd"},{"box_num":"1","prosno_md5":"545cda9ac049e8a6ca785370baa4c893"},{"box_num":"1","prosno_md5":"545cda9ac049e8a6ca785370baa4c893"},{"box_num":"1","prosno_md5":"545cda9ac049e8a6ca785370baa4c893"},{"box_num":"1","prosno_md5":"545cda9ac049e8a6ca785370baa4c893"},{"box_num":"1","prosno_md5":"545cda9ac049e8a6ca785370baa4c893"},{"box_num":"2","prosno_md5":"b9b887b6d81825540b584e503350246b"},{"box_num":"3","prosno_md5":"87415b41b663fbb5d78629d303bf53d0"},{"box_num":"3","prosno_md5":"87415b41b663fbb5d78629d303bf53d0"},{"box_num":"3","prosno_md5":"59d99b563381a33cfaa5c4ebaf8025a1"},{"box_num":"3","prosno_md5":"776d4c82e30f90484d6f57f7375901b6"},{"box_num":"3","prosno_md5":"9a85df0bf0badae7fbfcca5d70165de4"},{"box_num":"3","prosno_md5":"690e41db5122f94de87ff4ece724000d"},{"box_num":"3","prosno_md5":"5ffe4ee06c146d9f419cc5b14181accb"},{"box_num":"3","prosno_md5":"a31cd466b4d9598c030bb6608d84b802"},{"box_num":"3","prosno_md5":"4595441a6eb1eed82d721e690554bdf2"},{"box_num":"3","prosno_md5":"2bf1fe738538371ea8c56b090e0ea934"},{"box_num":"3","prosno_md5":"8faa5cc29938e2b1e1090eda9e21ebc2"},{"box_num":"3","prosno_md5":"545cda9ac049e8a6ca785370baa4c893"},{"box_num":"3","prosno_md5":"545cda9ac049e8a6ca785370baa4c893"},{"box_num":"3","prosno_md5":"545cda9ac049e8a6ca785370baa4c893"},{"box_num":"3","prosno_md5":"545cda9ac049e8a6ca785370baa4c893"},{"box_num":"3","prosno_md5":"545cda9ac049e8a6ca785370baa4c893"},{"box_num":"3","prosno_md5":"545cda9ac049e8a6ca785370baa4c893"},{"box_num":"3","prosno_md5":"545cda9ac049e8a6ca785370baa4c893"},{"box_num":"3","prosno_md5":"545cda9ac049e8a6ca785370baa4c893"},{"box_num":"3","prosno_md5":"03475f4998fe0190da9be405521130cf"},{"box_num":"3","prosno_md5":"09f9c31a1db4c06a9e3eff7e93969fc7"},{"box_num":"3","prosno_md5":"9b07b091a5715e7de90e3907ae8e3db2"},{"box_num":"3","prosno_md5":"071326dbbfce4316f8c5a1aec778f17c"},{"box_num":"3","prosno_md5":"9fc2d0a7e6709dae36395d33325775d3"},{"box_num":"3","prosno_md5":"32d48d6dbd84ab334660dad4c68a8727"},{"box_num":"3","prosno_md5":"e6d2388dbd274cdee04a41763baf340f"},{"box_num":"3","prosno_md5":"2631cfec3f45489521473a8b13157752"},{"box_num":"3","prosno_md5":"d6d8db4d89d79859e2491c4a72efd8e8"},{"box_num":"3","prosno_md5":"747045556b1d2d9529a1250c66820126"},{"box_num":"3","prosno_md5":"5bab49670b5f668ef0ced066be7a590f"},{"box_num":"3","prosno_md5":"d583abc4bf0bde5a1106d414b5d83f98"},{"box_num":"3","prosno_md5":"abf7685103494b084e7082ac8172e6c1"},{"box_num":"3","prosno_md5":"bb882bb8c9dd4a0414fd03ccca6cf922"},{"box_num":"3","prosno_md5":"afeb209fcdfdb39048a3aca7df7db9a5"},{"box_num":"3","prosno_md5":"09b55bc6c98796209ba3c1a7cfe29334"},{"box_num":"3","prosno_md5":"eddf2e6eec3f9dbe7d3b102b0f85cdb4"},{"box_num":"3","prosno_md5":"c5e553f69ca524c3ebfd3bc1f5f1e187"},{"box_num":"3","prosno_md5":"492c8ae33cb48d78ffb4b81a5b08cc12"},{"box_num":"3","prosno_md5":"0d3e6267569a4a58484d7cc753142d2f"},{"box_num":"3","prosno_md5":"1081f7e8f9fff181433ee5094717d9a5"},{"box_num":"3","prosno_md5":"e5d104ff891540588c579909b5e27760"},{"box_num":"3","prosno_md5":"9aef046e53575c3678085ce9cf60a98e"},{"box_num":"3","prosno_md5":"c737eb08daf4686e5477fa66bcb0be1f"},{"box_num":"3","prosno_md5":"942ff5796e68c056f9362fb41f78a616"},{"box_num":"3","prosno_md5":"0d3e6267569a4a58484d7cc753142d2f"},{"box_num":"3","prosno_md5":"c047ce5f63391ba36afdf329a9191d5c"},{"box_num":"3","prosno_md5":"814a8d21184ffad8c0e316e9cfa66dd6"},{"box_num":"3","prosno_md5":"dea500ed7a8d034608f0da5e1de3eb59"},{"box_num":"3","prosno_md5":"eb876cf355380b46ec41b7637e3b5d30"},{"box_num":"3","prosno_md5":"b1f443335dca605f0bf06a4579a38aa0"},{"box_num":"4","prosno_md5":"fc7cee9dcb2984f3400f122fcf07f318"},{"box_num":"4","prosno_md5":"88bb78547d2d3fb0ea3aba32ae32b939"},{"box_num":"4","prosno_md5":"862fc76f61f6f4b601687164dd6364c4"},{"box_num":"4","prosno_md5":"14ced585b136a813897fa3f9d623e0d4"},{"box_num":"4","prosno_md5":"4313a0a223b94825ab422610461ebf62"},{"box_num":"4","prosno_md5":"917fe1555a9e1665007fe2f38695ae94"},{"box_num":"4","prosno_md5":"97106676c18fe581e86659c20a7d4a2b"},{"box_num":"4","prosno_md5":"370df2c5f83cb01c17415cd560190e2d"},{"box_num":"4","prosno_md5":"a841242e8b1f9966b00f76ac76f57f44"},{"box_num":"4","prosno_md5":"06a314fcc606cf979f88b2ec041d7b03"},{"box_num":"4","prosno_md5":"6af789128d624b3bde7dfb972f443ed8"},{"box_num":"4","prosno_md5":"764e9b185bbd53b4fb61b0824397dffe"},{"box_num":"4","prosno_md5":"73d0425d5c1719c86aeab06a32d6c11a"},{"box_num":"4","prosno_md5":"b2a6ca4f6d6e12bd396edd547ddbf8af"},{"box_num":"4","prosno_md5":"55531b19578145cc8e4f5f7142fa4bec"},{"box_num":"4","prosno_md5":"322175ee65f43d9bb6f343fb145f0d89"},{"box_num":"4","prosno_md5":"7546d547fae5ffd0638b1bbd8775b316"},{"box_num":"4","prosno_md5":"211a30d3ca54a86be526c46fc318b34e"},{"box_num":"4","prosno_md5":"3bb2d76841081a2aaf7eaae8621afec4"},{"box_num":"4","prosno_md5":"d9e6f217aa4da6a3582a894e3f27477a"},{"box_num":"4","prosno_md5":"fc7cee9dcb2984f3400f122fcf07f318"},{"box_num":"4","prosno_md5":"c0fa2ea81431ceb395c6e2d60e73a53d"},{"box_num":"4","prosno_md5":"d690a3f429eec0c41f11ad325d98e299"},{"box_num":"4","prosno_md5":"764e9b185bbd53b4fb61b0824397dffe"},{"box_num":"4","prosno_md5":"fc7cee9dcb2984f3400f122fcf07f318"},{"box_num":"4","prosno_md5":"29e14d6dea7aeb03b6733486b6fb101e"},{"box_num":"4","prosno_md5":"b17f241b4e8ebc2cbe086167bfa48945"},{"box_num":"4","prosno_md5":"0b3f6caaecd3468de5c882663ff6677d"},{"box_num":"4","prosno_md5":"c99bf2168772a76883528ee09d15ce10"},{"box_num":"4","prosno_md5":"7a1bfb3f4aebb6f6c01750089f785f3c"},{"box_num":"4","prosno_md5":"29e14d6dea7aeb03b6733486b6fb101e"},{"box_num":"4","prosno_md5":"b2a6ca4f6d6e12bd396edd547ddbf8af"},{"box_num":"4","prosno_md5":"11459a65fb5452828333c4bc9b3b82a0"},{"box_num":"4","prosno_md5":"94144dbeb701ffcc642786bd4446a348"},{"box_num":"5","prosno_md5":"486373d1f1ac3063cb439147e0d4e90b"},{"box_num":"6","prosno_md5":"486373d1f1ac3063cb439147e0d4e90b"},{"box_num":"7","prosno_md5":"897a4085e0fe6d8671a0635c69ffc220"},{"box_num":"7","prosno_md5":"897a4085e0fe6d8671a0635c69ffc220"},{"box_num":"7","prosno_md5":"897a4085e0fe6d8671a0635c69ffc220"},{"box_num":"8","prosno_md5":"fc7cee9dcb2984f3400f122fcf07f318"},{"box_num":"9","prosno_md5":"3bd5fcfb29190ed77c88c4dfa0cdab9a"},{"box_num":"9","prosno_md5":"ad05814bea4ce0d39b8be5c116351e64"},{"box_num":"9","prosno_md5":"24917e5d7bd83f859775be5fb30180e4"},{"box_num":"9","prosno_md5":"a63bfecb9eaef00cadab8ef05aeb409d"},{"box_num":"9","prosno_md5":"447e19d832dbc0b1be44a3bb949333fb"},{"box_num":"9","prosno_md5":"6c67bdf994473de65ab5fa25b20102b9"},{"box_num":"9","prosno_md5":"26c931d965cd987954340be393040895"},{"box_num":"9","prosno_md5":"871374c08905b901feeabaeb305d295e"},{"box_num":"9","prosno_md5":"280c5678cf95a1ed49c330e2e397ed92"},{"box_num":"9","prosno_md5":"0b26479d7c4088bdd0c722cb50652ab8"},{"box_num":"9","prosno_md5":"7832c5cba2c3117c32b76eea696e41f0"},{"box_num":"9","prosno_md5":"b497ddc26e3d5d557d05183199b3503e"},{"box_num":"9","prosno_md5":"917336bc48d70f9b4e029b5244925bcf"},{"box_num":"9","prosno_md5":"4840244223799ca99fc29242b6cd905d"},{"box_num":"9","prosno_md5":"e7528464ff306b2e3e30dcb5ccedf5e9"},{"box_num":"9","prosno_md5":"ee6fb750e7de2e33711444617a43f662"},{"box_num":"9","prosno_md5":"ac5c36b40f5f2a798a02a79d34dd7390"},{"box_num":"9","prosno_md5":"b4cea252f693c7d7b87b397867fa66e3"},{"box_num":"9","prosno_md5":"af90ea114a91bba01c80883a3e2e16f9"},{"box_num":"9","prosno_md5":"d398d522a3d09e6c5d7bba7215ad3712"},{"box_num":"9","prosno_md5":"ecd67cab84be43135e925519382d11c0"},{"box_num":"9","prosno_md5":"d0797b99e451fcdaccd58931a867233d"},{"box_num":"9","prosno_md5":"e27cb23e261dc654b3e513d90ffc2cdb"},{"box_num":"9","prosno_md5":"ecd67cab84be43135e925519382d11c0"},{"box_num":"9","prosno_md5":"d3aa6a22ebfaba592241f993abfbfec0"},{"box_num":"9","prosno_md5":"97c0b7671dc3b7013eaba8cc4d3ea9e1"},{"box_num":"9","prosno_md5":"267f7e5d8b0b24f2008232609da7ec3a"},{"box_num":"9","prosno_md5":"38c36f5bb6a1b38345b1b987d3dacc54"},{"box_num":"9","prosno_md5":"504dd4edef4d3c67a81505410418978d"},{"box_num":"9","prosno_md5":"e3a7d453118cbf4e4cbaf749cd2c6218"},{"box_num":"9","prosno_md5":"9d4334edee80e7f6638855130c361656"},{"box_num":"9","prosno_md5":"3590fa1bffd8245c9f11d7d1b1839674"},{"box_num":"9","prosno_md5":"f1b91248e1219c3362c4209fba2a7214"},{"box_num":"9","prosno_md5":"ad985ba05c5f4acb93fc21ec0967f9ca"},{"box_num":"9","prosno_md5":"45c9cf5dcf9506b63e0c36787a09fcf6"},{"box_num":"9","prosno_md5":"fc4720a4236aa34c485afd475eceb29a"},{"box_num":"9","prosno_md5":"48e6694274ddedcca5d3e0d31b3458f1"},{"box_num":"9","prosno_md5":"67afef0be2a3a81bb8d2af83a097e9a9"},{"box_num":"9","prosno_md5":"01cabecf299b27c1f23fdbb7512127b6"},{"box_num":"9","prosno_md5":"82749c47332bd22f90bed9dfbc0e493d"},{"box_num":"9","prosno_md5":"aac7c28701d42286a3176b52fefc1fc5"},{"box_num":"9","prosno_md5":"97dfa59b4192bd1571091d49e3ad5128"},{"box_num":"9","prosno_md5":"d497391f4e1449f13289b587cc21e099"},{"box_num":"9","prosno_md5":"7a4eedb6faadb812ab5ec1e3cb1ba4ea"},{"box_num":"9","prosno_md5":"fa6d0230ebc8d87e815e4fc91b26bcdb"},{"box_num":"9","prosno_md5":"e27cb23e261dc654b3e513d90ffc2cdb"},{"box_num":"9","prosno_md5":"3345e514de71fdbf511e5873a02c51e2"},{"box_num":"9","prosno_md5":"5b6fd64f5a91206711747ff3808a9681"},{"box_num":"9","prosno_md5":"745c9e91d4a6e74f5d156ae0e5b37f06"},{"box_num":"9","prosno_md5":"2b93019c59faab1bcd13b6700966dc4b"},{"box_num":"10","prosno_md5":"bb2ecc24aa753063ed8a08e880cdf331"},{"box_num":"10","prosno_md5":"f40d6412f119b889af598abf9c86c4ea"},{"box_num":"10","prosno_md5":"b5c50f3e10c720762d7c46e2c33b3169"},{"box_num":"10","prosno_md5":"2dbb94fbe51e94ac9bec9b5f4e6d89aa"},{"box_num":"10","prosno_md5":"9213cceea83654c31479118a35959ce2"},{"box_num":"10","prosno_md5":"229f69e9f466881d3492769957410fa7"},{"box_num":"10","prosno_md5":"1a3c825c5624e21cf088cc813783b317"},{"box_num":"10","prosno_md5":"dc7281802b300fcfc1615f82de1a44f6"},{"box_num":"10","prosno_md5":"038be063fae010aa23ceea0facef00bd"},{"box_num":"10","prosno_md5":"be22af234a3524510f9151bc29cad8af"},{"box_num":"10","prosno_md5":"fdfab549d0de7ed31ab9a383a166a68c"},{"box_num":"10","prosno_md5":"eac8a2d2156de70f0bf1668249e09aba"},{"box_num":"10","prosno_md5":"d7c80b8a504c0a5690bff9f4a4e45a09"},{"box_num":"10","prosno_md5":"24c8e0261441316656254ecf134d58f8"},{"box_num":"10","prosno_md5":"325a2d6fbe422206bca5aa321cc9f661"},{"box_num":"10","prosno_md5":"4c9b55515771755468450f404e83ed9c"},{"box_num":"10","prosno_md5":"fa2501847dc5fa454ec2283ec0b36642"},{"box_num":"10","prosno_md5":"caeb128d282ffd78d5cd5e46fc9b4875"},{"box_num":"10","prosno_md5":"93650e2bdabc0c42d45203d27195ef76"},{"box_num":"10","prosno_md5":"e35435a10f71db1ab274f0b3e63c6cfe"},{"box_num":"10","prosno_md5":"cb7e07f9a87dd89ec64a920377ea7a2c"},{"box_num":"10","prosno_md5":"24c8e0261441316656254ecf134d58f8"},{"box_num":"10","prosno_md5":"6a1517c9ad8c59246b5edffee3a68ff5"},{"box_num":"10","prosno_md5":"6ad8392928099ef54905eab10b61785f"},{"box_num":"10","prosno_md5":"f852c0da07e000ae614edea877494bcc"},{"box_num":"10","prosno_md5":"229f69e9f466881d3492769957410fa7"},{"box_num":"10","prosno_md5":"d9c8522becb4292f52aecde7446793e0"},{"box_num":"10","prosno_md5":"d51078b715041f5831736c005db0a54d"},{"box_num":"10","prosno_md5":"0ceb1e1cb3eba570f74a4bfba62c305c"},{"box_num":"10","prosno_md5":"13df16cee8c859ce4375594e975e3663"},{"box_num":"10","prosno_md5":"dfd05465c3e3112fe26ee145fc7add5c"},{"box_num":"10","prosno_md5":"54b915ea9e3f74e9c5f67255c7c47095"},{"box_num":"10","prosno_md5":"6eaeab48d2148bee6127c1e88a932ef9"},{"box_num":"10","prosno_md5":"13df16cee8c859ce4375594e975e3663"},{"box_num":"10","prosno_md5":"fbd65af8cf0724a1c142b693fd8cf602"},{"box_num":"10","prosno_md5":"201bf9a4607943439cbf0d8a22cace31"},{"box_num":"10","prosno_md5":"fa2501847dc5fa454ec2283ec0b36642"},{"box_num":"10","prosno_md5":"9213cceea83654c31479118a35959ce2"},{"box_num":"10","prosno_md5":"2eabeed07c2b526f5e17bfdb616451b1"},{"box_num":"10","prosno_md5":"98baffe4fead4d16b74ac269cf870898"},{"box_num":"10","prosno_md5":"e0e94c088a43f2c8c7fbb26837bfc5db"},{"box_num":"10","prosno_md5":"0b11b0591fd8216082e9dc43e3e776bc"},{"box_num":"10","prosno_md5":"d7c80b8a504c0a5690bff9f4a4e45a09"},{"box_num":"10","prosno_md5":"a4ce08f0b38ab6bd184b8113848f05a5"},{"box_num":"10","prosno_md5":"118828b9f89dc1c384fe40eb996822e2"},{"box_num":"10","prosno_md5":"4325ba3890681936d4c2747dd6c8fb14"},{"box_num":"10","prosno_md5":"6d2489dd98abe473ee09ae179020eea7"},{"box_num":"10","prosno_md5":"9213cceea83654c31479118a35959ce2"},{"box_num":"10","prosno_md5":"c7d7bf3f079cefe37b097be5fbb2ff70"},{"box_num":"10","prosno_md5":"1483a12c36dcd9de02f7d83bc60cd8d4"},{"box_num":"11","prosno_md5":"e22ffbb8758aa41646b0bb73f89f0639"},{"box_num":"11","prosno_md5":"5576a42c292f6a2ceb07d6c695618d69"},{"box_num":"11","prosno_md5":"2cad8a0c11b4a997edeec3f3c83826c1"},{"box_num":"11","prosno_md5":"2cad8a0c11b4a997edeec3f3c83826c1"},{"box_num":"11","prosno_md5":"6c67bdf994473de65ab5fa25b20102b9"},{"box_num":"11","prosno_md5":"f1b91248e1219c3362c4209fba2a7214"},{"box_num":"11","prosno_md5":"e7a78638542b20328a1db376111927b9"},{"box_num":"11","prosno_md5":"2cad8a0c11b4a997edeec3f3c83826c1"},{"box_num":"11","prosno_md5":"83d91838167ace22d7a921bb2d76a46a"},{"box_num":"11","prosno_md5":"5afe82c82c3861bdda97b923546565b2"},{"box_num":"11","prosno_md5":"ec03d07563f91045d64cc9c82c1af739"},{"box_num":"11","prosno_md5":"c6b76d58ccea0c3033c1d33254691707"},{"box_num":"11","prosno_md5":"eff7f2c9fa7fd3d13222ece38c804004"},{"box_num":"11","prosno_md5":"e67088062efd78c4cf3694b24c8505ea"},{"box_num":"11","prosno_md5":"c5e04646172696fe4c9b78686a732391"},{"box_num":"11","prosno_md5":"f0e738b13a802eaccecc3a3eb5dc4225"},{"box_num":"11","prosno_md5":"d3aa6a22ebfaba592241f993abfbfec0"},{"box_num":"11","prosno_md5":"f18a21a93c86131187dddc056fc4e217"},{"box_num":"11","prosno_md5":"17b91b48f1c9ae1d26ad8d198bca88d8"},{"box_num":"11","prosno_md5":"917336bc48d70f9b4e029b5244925bcf"},{"box_num":"11","prosno_md5":"5310f04f54ea46058bf38da05d6a5d17"},{"box_num":"11","prosno_md5":"8ba5b4f3bef22363dafa238f21091327"},{"box_num":"11","prosno_md5":"e67088062efd78c4cf3694b24c8505ea"},{"box_num":"11","prosno_md5":"a4d3f271d50697bd9412dbdae79fcd2d"},{"box_num":"11","prosno_md5":"02114001f908c87c73e1a24ff8202b57"},{"box_num":"12","prosno_md5":"200923b915710753a3bffeb2c2dea7e5"},{"box_num":"13","prosno_md5":"30feea0dbe5f987c03dfca6bac1eb361"},{"box_num":"14","prosno_md5":"6ad8392928099ef54905eab10b61785f"},{"box_num":"14","prosno_md5":"e00ed9ada9898ce62b504c73fb1e5a6e"},{"box_num":"14","prosno_md5":"7507076b0e07c7a6fd05424b33b14b5f"},{"box_num":"14","prosno_md5":"3590fa1bffd8245c9f11d7d1b1839674"},{"box_num":"14","prosno_md5":"01cabecf299b27c1f23fdbb7512127b6"},{"box_num":"14","prosno_md5":"9b0e7717be7105cdbc6d052fd7f9bb5a"},{"box_num":"14","prosno_md5":"c1e78411577962c1892b41578a59e4b5"},{"box_num":"15","prosno_md5":"5840fc24090f181e4dca10aac8a044df"},{"box_num":"15","prosno_md5":"e84fa918b283d1b07597fd946dc6386b"},{"box_num":"15","prosno_md5":"637546aedf9fc79e4df2d4480925e05f"},{"box_num":"15","prosno_md5":"850bc647e2a7d1203efb93eb7362f1aa"},{"box_num":"15","prosno_md5":"6661f703585b980a0603e08549f1f760"},{"box_num":"15","prosno_md5":"8e4d7b029d9c7530a3739040f09c233a"},{"box_num":"15","prosno_md5":"e84fa918b283d1b07597fd946dc6386b"},{"box_num":"15","prosno_md5":"899cecf3d6e616c6f93ba0b04f72b648"},{"box_num":"15","prosno_md5":"bc4ab015286441d9dfa29c0e26c9cb16"},{"box_num":"15","prosno_md5":"8e4d7b029d9c7530a3739040f09c233a"},{"box_num":"15","prosno_md5":"8e4d7b029d9c7530a3739040f09c233a"},{"box_num":"15","prosno_md5":"7a995b57dff8050be2fdafbd4ddd3411"},{"box_num":"15","prosno_md5":"0faa0844c75e935afcc2126017bb7fe6"},{"box_num":"16","prosno_md5":"48b094c4ce4d32b3aa2b1c359ad51dfc"},{"box_num":"16","prosno_md5":"48b094c4ce4d32b3aa2b1c359ad51dfc"},{"box_num":"16","prosno_md5":"48b094c4ce4d32b3aa2b1c359ad51dfc"},{"box_num":"16","prosno_md5":"48b094c4ce4d32b3aa2b1c359ad51dfc"},{"box_num":"16","prosno_md5":"48b094c4ce4d32b3aa2b1c359ad51dfc"},{"box_num":"16","prosno_md5":"48b094c4ce4d32b3aa2b1c359ad51dfc"},{"box_num":"16","prosno_md5":"48b094c4ce4d32b3aa2b1c359ad51dfc"},{"box_num":"16","prosno_md5":"48b094c4ce4d32b3aa2b1c359ad51dfc"},{"box_num":"16","prosno_md5":"5a2e07e03dfa98d910b6f615cd916187"},{"box_num":"16","prosno_md5":"54a4ffe4f77789529be9ba70ca1f710b"},{"box_num":"16","prosno_md5":"7a3925602d34b078e4c7cdfc91ad67fb"},{"box_num":"16","prosno_md5":"9c3df40d1d288ec1895c9628f7a510bd"},{"box_num":"16","prosno_md5":"caee8a4e8560b4c363850cd3f6dcc20c"},{"box_num":"16","prosno_md5":"be008736b4a7d10f58ae7bfe23c5c0a5"},{"box_num":"16","prosno_md5":"7a3925602d34b078e4c7cdfc91ad67fb"},{"box_num":"16","prosno_md5":"7592273622b6cf947d2a95afe1b295ca"},{"box_num":"16","prosno_md5":"1745c68633f4391aa6caa9f3c66e85fe"},{"box_num":"16","prosno_md5":"1745c68633f4391aa6caa9f3c66e85fe"},{"box_num":"16","prosno_md5":"db380822b1671fc2fd2dad042b8ff149"},{"box_num":"16","prosno_md5":"7d3a7bb89714b65b06f09ec2f70be91f"},{"box_num":"16","prosno_md5":"7d3a7bb89714b65b06f09ec2f70be91f"},{"box_num":"16","prosno_md5":"4c5f03a7c0e57a81ad759b809d53c27f"},{"box_num":"16","prosno_md5":"5eb1828b1a05c13c0edf666de96c06fa"},{"box_num":"17","prosno_md5":"8aa763283e8cdd037fcff3f178e40f91"},{"box_num":"17","prosno_md5":"d403ba013d0702ffe698e4d86501d62a"},{"box_num":"17","prosno_md5":"186d0d103a94de244dd8de56e96d8f1c"},{"box_num":"17","prosno_md5":"a700123ec91e9d6e6ce5edb227e27c3b"},{"box_num":"17","prosno_md5":"b90d64459302fc531d44099d9af4f0aa"},{"box_num":"17","prosno_md5":"c35c759fa1c821da3e3bc118cec69d09"},{"box_num":"17","prosno_md5":"64e6edc49273981945534aa3abed6525"},{"box_num":"17","prosno_md5":"99144dac69562c1aa0f1f89939f3168a"},{"box_num":"17","prosno_md5":"450e54e93006a0eb274e7c4ee214d99f"},{"box_num":"18","prosno_md5":"6ebc4fa79ad6ca0499c70b5b7300344e"},{"box_num":"19","prosno_md5":"19fff0d1ada18aa9b82279912d1763af"},{"box_num":"20","prosno_md5":"50184bf3b1b8625223adfc4be8961e24"},{"box_num":"20","prosno_md5":"f369ea9ef80b144f5320ef9e16b0c425"},{"box_num":"20","prosno_md5":"f369ea9ef80b144f5320ef9e16b0c425"},{"box_num":"20","prosno_md5":"f369ea9ef80b144f5320ef9e16b0c425"},{"box_num":"20","prosno_md5":"f369ea9ef80b144f5320ef9e16b0c425"},{"box_num":"20","prosno_md5":"f369ea9ef80b144f5320ef9e16b0c425"},{"box_num":"20","prosno_md5":"f369ea9ef80b144f5320ef9e16b0c425"},{"box_num":"20","prosno_md5":"8914bd54187318bcbf1c246250c33f30"},{"box_num":"20","prosno_md5":"f369ea9ef80b144f5320ef9e16b0c425"},{"box_num":"20","prosno_md5":"f369ea9ef80b144f5320ef9e16b0c425"},{"box_num":"20","prosno_md5":"cf01532ffb150546c661f59650f3aa56"},{"box_num":"20","prosno_md5":"cf01532ffb150546c661f59650f3aa56"},{"box_num":"20","prosno_md5":"5e0ff457410bec7eb04b21097e0743f7"},{"box_num":"20","prosno_md5":"4543d36d4579c3868ce2a53418fa3ce8"},{"box_num":"21","prosno_md5":"aa80e8565515f197784c301b4c8a4cfb"},{"box_num":"21","prosno_md5":"aa80e8565515f197784c301b4c8a4cfb"},{"box_num":"21","prosno_md5":"aa80e8565515f197784c301b4c8a4cfb"},{"box_num":"21","prosno_md5":"aa80e8565515f197784c301b4c8a4cfb"},{"box_num":"21","prosno_md5":"aa80e8565515f197784c301b4c8a4cfb"},{"box_num":"21","prosno_md5":"aa80e8565515f197784c301b4c8a4cfb"},{"box_num":"21","prosno_md5":"aa80e8565515f197784c301b4c8a4cfb"},{"box_num":"21","prosno_md5":"aa80e8565515f197784c301b4c8a4cfb"},{"box_num":"21","prosno_md5":"aa80e8565515f197784c301b4c8a4cfb"}]';  // 测试数据json字符串
$testDataArr = json_decode($testDataStr,true);        // 把字符串转成数组
// print_r($testDataArr); die;

$AutoDistributeDec = new AutoDistributeDec();
$AutoDistributeDec->handleOrderDetail($testDataArr); // 组装合单之前的数据
$decToBox = $AutoDistributeDec->getBestSplit();           // 合并型号组单
print_r($decToBox); die;

Copy the code

One piece of test data has been provided in demo.php. Group single principle such as code comments, follow the head and tail pointer method used in question 1.

For optimal solutions, dynamic programming is required, with each term iterating through the search for a matching [optimal merge term]. The idea is some, but the code still needs some time, because to consider the balance of time complexity and space complexity, and so on to solve the update to the next article.

Finally, the original is not easy, if you think this article is useful to you, please kindly like, comment or forward this article, the author needs some positive feedback, thank you.