#include <iostream>using namespace std;int m[100][100];int min (int a,int b) {return (a<b)? A:b;} int max (int a,int b) {return (a>b) a:b;} void knapsack (int v[],int w[],int c,int n) {int jmax=min (W[N],C); for (int j=0;j<=jmax;j++) m[n][j]=0;for (j=w[n];j< =c;j++) m[n][j]=v[n];for (int i=n-1;i>1;i--) {jmax=min (w[i],c); for (j=0;j<=jmax;j++) m[i][j]=m[i+1][j];for (j=w [i];j<=c;j++) M[i][j]=max (M[i+1][j],m[i+1][j-w[i]]+v[i]);} M[1][c]=m[2][c];if (C>=w[1]) M[1][c]=max (m[2][c],m[2][c-w[1]]+v[1]);} void Trace (int w[],int c,int n,int x[]) {for (int i=1;i<n;i++) if (M[i][c]==m[i+1][c]) x[i]=0;else{x[i]=1;c-=w[i];} X[n]= (M[n][c])? 1:0;} void Main () {int c=100,v[3],t[3],x[3];//cout<< "input Volume:" <<endl;for (int i=1;i<=3;i++) cin>>t[i];// cout<< "Input value:" <<endl;for (i=1;i<=3;i++) cin>>v[i];knapsack (v,t,100,3); trace (t,100,3,x); int Vsum=0;for (i=1;i<=3;i++) Vsum+=v[i]*x[i];cout<<vsum<<endl;}
Huawei machine Test-item Basket (advanced 160 points, including volume value: Greedy algorithm)