//背包问题w[] = {0,1,2,3,4},v[] ={0,1,2,3,4} 第一个为0
public static void bagProblem(int w[] ,int v[],int maxWeight){
int n = w.length-1;//物品数量
int c[][] = new int[n+1][m+1];
for(int i=0;i<=n;i++){
for(int j=0;j<=m;j++){
c[i][j] = 0;
}
}
for(int i=1 ;i<=n;i++){
for(int j=1;j<=m;j++){
if(w[i]<=j){
if(v[i]+c[i-1][j-w[i]]>c[i-1][j]){
c[i][j]= v[i]+c[i-1][j-w[i]]; //选择
}else{
c[i][j]=c[i-1][j];//价值没有变大,不选
}
}else{
c[i][j]=c[i-1][j];//剩余质量不够,不选
}
}
}
System.out.println("最优解:"+c[n][m]);
int weight = m;
for(int i=n;i>0;i--){
if(c[i][weight]==c[i-1][weight]){
}else{
System.out.println("选择第 "+i+" 件物品");
weight = weight-w[i];
}
}
}