最优装载问题(Optimal loading problem)
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
最优装载问题(Optimal loading problem)最优装载问题(Optimal loading problem)
Optimal loading problem
Problem description
There are n containers to be loaded with 1 ships with carrying capacity of C respectively, in which the weight of the first I container is wi. The optimal loading problem requires that the container be loaded with as many containers as possible in the case of unlimited loading volume and find a loading scheme
input
The input has several sets of test data (no more than 20 groups).
Each set of test data has 2 lines:
The first line is the container number N and the ship carrying capacity C (n<1000, c<65535);
The second line has n integers W1, w2,... Wn, integers are separated by one space, and these n integers represent the weight of the n containers in turn, (0 output You are required to output 3 lines of each test data in the input: The output of "Case #" in the first line, which "#" is the number of test data (starting from 1). On the second line, two integers bestn and leftc, where bestn is the maximum number of containers loaded by the vessel, and leftc is the maximum remaining load of the ship corresponding to the bestn. Output a 0-1 string x1x2 on the third line... Xn, in which x1x2... Xn is the specific loading scheme corresponding to the bestn. The xi=1 indicates that the I container is mounted on the vessel, while the xi=0 indicates that the I container is not mounted on the vessel. The loading scheme corresponding to the bestn may not be unique, such as 3 containers with a weight of 40, 10, and 40. If the carrying capacity of the vessel is 50, then only 2 containers can be loaded on board, so there are two options for loading, 110 and 011. In order to make the output results only, we agreed to n long 0-1 string to the maximum lexicographic order to meet the requirements of the loading scheme, in this case should be 110. sample input 350 401040 537 1030243540 sample output Case 1 20 One hundred and ten Case 2 23 Ten thousand and one hundred #include //template Class MaxHeap; //template Class HeapNode; Class bbnode{ Friend, void, AddLiveNode (MaxHeap&, bbnode*, int, int, int); Friend, int, MaxLoading (int*, int, int, int *); //friend class adjacencygraph; Private: Bbnode *parent; / / pointer to the parent node. Int Lchild; / / left son node mark }; //////////////////////////////////////////////////////////////////// /// //template Class HeapNode{ Friend, void, AddLiveNode (MaxHeap&, bbnode*, int, int, int); Friend, int, MaxLoading (int*, int, int, int *); Public: Operator int () const {return uweight;} / / private: