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,finish;
double totaltime;
start=clock();
float c = 100;
float w[] = {0,23,15,26,46,41,29};//下标从1开

本文介绍了贪心算法在最优装载问题中的应用,讨论了如何在有限载重下最大化装载集装箱的数量。接着,阐述了单源最短路径问题,并以Dijkstra算法为例进行详细解释,包括算法的时间复杂性分析和具体测试数据的处理。
最低0.47元/天 解锁文章
2209

被折叠的 条评论
为什么被折叠?



