某运输公司为10个客户配送货物,假定提货点就在客户1所在的位置,从第i个客户到第j个客户的路线距离(单位公里)用下面矩阵中的 位置上的数表示(其中 表示两个客户之间无直接的路线到达)。十乘十矩阵。
A =
0 50 Inf 40 25 Inf 30 Inf 50 Inf
50 0 30 Inf 35 50 Inf 60 Inf Inf
Inf 30 0 15 Inf 30 50 25 Inf 60
40 Inf 15 0 45 30 55 20 40 65
25 15 Inf 45 0 60 10 30 Inf 55
Inf 50 30 30 60 0 25 55 35 Inf
30 Inf 50 Inf 10 25 0 30 45 60
Inf 60 25 20 30 55 30 0 10 Inf
20 Inf Inf 40 Inf 15 25 45 0 20
35 20 10 45 20 Inf 60 Inf 30 0`
问题2.现运输公司派了一辆大的货车为这10个客户配送货物,假定这辆货车一次能装满10个客户所需要的全部货物,请问货车从提货点出发给10个客户配送完货物后再回到提货点所行使的尽可能短的行使路线?对所设计的算法进行分析。
#include<iostream>
#include<stdlib.h>
using namespace std;
#define inf 99999
struct Assemble
{
int a;
int b[10];
};
int Hld(int i,Assemble S,int A[10][10])
{
int l;
if (S.a==0)
{
l=A[0][i-1];
return l;
}
else
{
Assemble s;s.a=S.a-1;int L[10];
for(int j=0;j<S.a;j++)
{
int n1=S.b[j];int m=0;
while(m<S.a-1)
{
if(m!=j)
{
s.b[m]=S.b[m];
}
else
{
s.b[m]=S.b[m+1];
}m++;
}
L[j]=A[n1-1][i-1]+Hld(n1,s,A);
}
for(int j=0;j<S.a;j++)
{
if(L[j]>L[j+1])
l=L[j+1];
}
return l;}
}
void main()
{
int A[10][10]={0,50,inf,40,25,inf,30,inf,50,inf,50,0,30,inf,35,50,inf,60,inf,inf,inf,30,0,15,inf,30,50,25,inf,60,40,inf,15,0,45,30,55,20,40,65,25,15,inf,45,0,60,10,30,inf,55,inf,50,30,30,60,0,25,55,35,inf,30,inf,50,inf,10,25,0,30,45,60,inf,60,25,20,30,55,30,0,10,inf,20,inf,inf,40,inf,15,25,45,0,20,35,20,10,45,20,inf,60,inf,30,0};
Assemble B;
B.a=9;
B.b[0]=2;B.b[1]=3;B.b[2]=4;B.b[3]=5;B.b[4]=6;B.b[5]=7;B.b[6]=8;B.b[7]=9;B.b[8]=10;
int length=Hld(1,B,A);
cout<<length;
system("pause");
}为什么程序不行呢????????错在哪啊??????