1、最优装载
有一批集装箱要装上一艘载重量为c的轮船。其中集装箱i的重量为Wi。最优装载问题要求确定在装载体积不受限制的情况下,将尽可能多的集装箱装上轮船。
该问题的形式描述:
(1)采用重量最轻者先装的贪心选择策略求最优解;
(2)算法的时间复杂性分析;
(3)针对以下测试数据,编写程序,给出运行结果。
例:c=100,n=6,w={23,15,26,46,41,29}
#include <iostream>
#include<time.h>
using namespace std;
const int N = 6;
template <class Type>
void Swap(Type &x,Type &y);
template<class Type>
void Loading(int x[], Type w[], Type c, int n);
template<class Type>
void SelectSort(Type w[],int *t,int n);
int main()
{
clock_t start,finis