There are n itmes and a backpack with size m. Given array A representing the size of each item and array V representing the value of each item.
What's the maximum value can you put into the backpack?
ไปฃ็
publicclassSolution {publicintbackpack(int m,int[] A,int[] V) {if (A ==null||A.length==0|| V ==null||V.length==0) {return0; }int[] f =newint[m +1];for (int i =0; i <A.length; i++) {for (int j = m; i >0; j--) {if (j >=A[i]) { f[j] =Math.max(f[j], f[j -A[i]] +V[i]); } } }return f[m]; }}