How to realize the optimal solution of "goods packaged separately"

background: the existing N items need to be packed into different express parcels. when the total tax in each package is less than 50 yuan, the goods in each package will be exempt from tax . It is required to ensure that the number of parcels is as small as possible and the tax as low as possible. The rules are as follows:

1: the number of parcels is as small as possible, the tax is as little as possible, and the goods are equally divided into each package as much as possible.
2: the total amount of goods per package (unit price * pieces) < = 2000 yuan
3: the weight of each package < = 6kg
4: pure health care or mixed parcels: total number of goods < = 10, number of cosmetics < = 1
5: pure cosmetic packages: number of goods < = 2
6: pure care packages: number of goods < = 6 pieces Chocolate, cereal, up to 15 pieces per package

Commodity test data:
clipboard.png


results of random method:

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e43f3e-4c17f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e43f3e-4c17f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?