- Status Definitions: \ (F_ {I, J} \) shows a front \ (I \) items placed capacity \ (J \) the maximum value attainable backpack
- Reasoning: The first \ (i \) items or leave
方程:\(f_{i,j}=max(f_{i-1,j},f_{i-1,j-C_i}+W_i)\)
$\Updownarrow $
* Space Optimization:- \ (f_j \) indicates the remaining \ (j \) is the maximum value of the package can be put down
- Equation: \ (F_j = max (F_j, F_ {+} J-C_i W_i) \) (reverse must enumeration \ (J \) , or can not meet the non aftereffect)
Code
for(register int i = 1 ; i <= n ; i++){
for(register int j = V ; j >= C[i] ; j--){
f[j] = max(f[j] , f[j - C[i]] + W[i]);
}
}