标签:isp 实验 define nbsp amp highlight -- printf load
//求解装载问题 #include<stdio.h> #define MAXN 20 int n,W; int maxw; int x[MAXN]; int minm = 32767; void disp(int n){ int i; printf("选取的集装箱:\n"); for(i=1;i<=n;i++) if(x[i] == 1) printf("选取第%d个集装箱\n",i); printf("总重量 = %d\n",maxw); } void Loading(int w[],int tw,int m,int op[],int i){ //考虑第i个集装箱 int j; if(i>n){ if(tw <= W && (tw > maxw || (tw == maxw && m < minm))){ maxw = tw; minm = m; for(j = 1;j<= n;j++) x[j] = op[j]; } } else{ op[i] = 1; if(tw + w[i] <= W) Loading(w,tw+w[i],m+1,op,i+1); op[i] = 0; if(m <= 2) Loading(w,tw,m,op,i+1); } } int main(){ int w[] = {0,5,2,6,4,3}; int op[MAXN]; //存放临时解 n = 5,W = 10; Loading(w,0,0,op,1); disp(n); }
标签:isp 实验 define nbsp amp highlight -- printf load
原文地址:https://www.cnblogs.com/Hqx-curiosity/p/12153415.html