这里有部分,可是有问题啊,大神们顺便看看
class BoardNode{
friend int
RBArrangeBoards(int **,int,int *&);
public:
operator int() const{return cd;
}
int len(int **,int ii);
private:
int *x,s,cd;
};
int BoardNode::len(int **conn,int ii)
{
for(int j=i+1,sum=0;i<=ii;i++){
int dist=x[i]>x[j]? x[i]-x[j]:x[j]-x[i];
sum+=conn[i][j]*dist;
}
return sum;
}
int
RBArrangeBoards (int **conn, int n, int *&bestx)
{
MinHeap<BoardNode>H(HeapSize) ;
BoardNode E;
E.x=new int[n+1];
E.s=0;E.cd=0;
for(int i=l;i<=n;i++)E.x[i]=i
int bestd=INT_MAX;
bestx=0;
while(E.cd<bestd){
if (E.S==n-1){
int ld=E.len(coon,n);
if(ld<bestd){
delete[]bestx;
bestx=E.x;bestd=ld;
}
elde{
for(int i=E.s+l;i<=n;i++){
BoardNode N;
N.x=new int[n+l];
N.s=E.s+l;
for (int j=l; j<=n;j++) N.x[j]=E.x[j];
N. x[N. s]=E. x[i];
N. x[i]=E. x[n.s];
N.cd=X.len(conn,N.s);
if (N.cd<=bestd) H.Insert (N) ;
else delete[]N. x ;
}
deletc[] E. x ;
try {H. DeleteMin(E) ;}
catch (OutOfBounds) (return bestd;}
}
while (true){
delete[] E.x;
try(H.DeleteMin(E) ;}
catch(...){ break;}
}
return bestd;
}
int main()
{
cin>>n;
p=new int[n+l];
int **B;
Make2DArray(B,n+1,nl+) ;
for(lnt i=l;i<=n-1;i++)
for (int
j=i+1; j<=n; j++)
cin>>[i][j] ;
cout<<BBArrangeBoards (B, n, p)<< endl ;
for (i=l;i<=n; i++)
cout<<p[i]<<" ";
cout<<endl;
return O;
}