How to understand the knapsack problem
This article mainly explains "how to understand the backpack problem," interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let Xiaobian take you to learn "how to understand the backpack problem"!
0-1 Two-dimensional bc of knapsack problem
#include #include #include using namespace std;const int N=1010;int n,m;int v[N],w[N];int f[N][N]; //valency sum int main(){ cin>>n>>m; for(int i=1;i>v[i]>>w[i]; //When 0 items are selected, the sum of values is 0, i.e. f[0][0~m] = 0; //Since it has been defined as a global variable, it has been initialized to 0, so it can not be written. for(int i=1;iv[i]>>w[i]; for(int i=1;i=v[i];j--) f[j]=max(f[j],f[j-v[i]]+w[i]); cout