p[k])>best){ best=nextNode->cp+p[k]; bestp=NewNode(nextNode,1,(float)best); } if((long)(nextNode->cp)>best){ best=nextNode->cp; bestp=NewNode(nextNode,0,(float)best); }} if(k<n-1){ if(nextNode->cw+w[k]<=c&&LUBound(k+1,nextNode->cw+w[k],nextNode->cp+p[k])>(float)be st){ ub=LUBound(k,nextNode->cw+w[k],nextNode->cp+p[k]); AddNode(NewNode(nextNode,1,ub)); } ub=ub=LUBound(k,nextNode->cw,nextNode->cp); if(ub>best) AddNode(NewNode(nextNode,0,ub)); }} PrintResult(); } void main(){ int c,n,i=0; int *p,*w; cout<<" 请输入背包容量值:"; cin>>c; cout<<" 请输入物品数:"; cin>>n; p=new int[n]; w=new int[n]; for(i=0;i<n;i++) {cout<<" 请输入第"<<i+1<<" 件物品的重量向量"<<endl;cin>>w[i]; } cout<<" 请输入价值向量"<<endl; for(i=0;i<n;i++) {cout<<" 请输入第"<<i+1<<" 件物品的重量向量"<<endl;cin>>p[i];} answer=new int[n]; Knap kanp(p,w,c,n); kanp.LCKnap(); }