#include
#include
#define N 100
#define MAX(a,b) a using namespace std;
struct goods{
int wight;
int value;
};
int n,bestValue,cv,cw,c;
int X[N],cx[N];
struct goods goods[N];
int KnapSack(int n,struct goods a[],int Cint x[])
{
int V[N][N+1];
for (int i=1;i<=n;i++)
for(int j=1;j<=c;j++)
if(j V[i][j]=V[i-1][j];
else
V[i][j]=MAX(V[i-1][j],v[i-1][j-a[i-1].wight]+a[i-1].value);
for(int i=n,j=c;i>0;i--)
{
if(V[i][j]>V[i-1][j])
{
x[i-1]=1;
j=j-a[i-1].wight;
}
else
x[i-1]=0;
}
return V[n][c];
}
int main()
{
printf("物品种类n:");
scanf("%d",&n);
printf("背包容量C:");
scanf("%d",&C);
for(int i=0;i
printf("物品%对的重量w[%d]及其价值V[%d]:",i+,i+1,i+1);
scanf("%d%d",&goods[i].wight,&goods[i].value);
}
}
}



