int MaxLoading(int w[],int c,int n,int bestx[]){//返回最右载重量 ofstream Outfile("/Users/CristinaSt/Documents/算法设计/test6/test2.txt"); Loading X; X.x = new int[n+1]; X.w = new int[n+1]; X.bestx = new int[n+1]; X.w = w; X.c = c; X.n = n; X.bestx = bestx; X.bestw = 0; X.cw = 0; X.r = 0; for (int i = 1; i <=n ; ++i) { X.r+=w[i]; } //计算最右载重量 X.Backtrack(1); for (int j = 1; j <=n ; ++j) { cout<<X.bestx[j]<<" "; Outfile<<X.bestx[j]; } delete[]X.w; delete[]X.bestx; delete[] X.x; return X.bestw; }
int MaxLoading(int w[],int c,int n,int bestx[]){ Loading X; X.x = new int[n + 1]; X.w = w; X.c = c; X.n = n; X.bestx = bestx; X.bestw = 0; X.cw = 0; X.r = 0; for(int i = 1;i <= n;i++){ X.r += w[i]; } X.Backtrack(1); return X.bestw; }
Type MaxLoading(Type w[], Type c, int n, int bestx[]) //返回最优载重量 { Loading<Type> X; // 初始化 X X.x = new int[n+1]; X.w = w; X.c = c; X.n = n; X.bestx = bestx; X.bestw = 0; X.cw = 0; // 初始化 r X.r = 0; for(int i=1; i<=n; i++) { X.r += w[i]; } X.Backtrack(1); delete []X.x; return X.bestw; }