Given_n_items with size Ai, an integer_m_denotes the size of a backpack. How full you can fill this backpack?
Notice
You can not divide any item into small pieces.
Example
If we have4items with size[2, 3, 5, 7], the backpack size is 11, we can select[2, 3, 5], so that the max size we can fill this backpack is10. If the backpack size is12. we can select[2, 3, 7]so that we can fulfill the backpack.
You function should return the max size we can fill in the given backpack.
public int backPackII(int m, int[] A, int V[]) {
int[] value=new int[m+1];
value[0]=0;
for(int i=0;i<A.length;i++){
for(int j=m;j>0;j--){
if(j>=A[i]){
value[j]=Math.max(value[j],value[j-A[i]]+V[i]);
}
}
}
return value[m];
}