二维(一样爆内存)
1 for(int i=1;i<=n;i++)//完全背包可以重复装相同的物品 2 for (int j = 0; j <= m; j++) { 3 f[i][j] = f[i - 1][j]; 4 if (j - v[i] >= 0)f[i][j]max(f[i][j], f[i][j - v[i]] + w[i]); 5 }
一维
1 for (int i = 1; i <= n; i++){ 2 for (int j = v[i]; j <= m; j++) { 3 dp[j] = max(dp[j], dp[j - v[i]] + w[i]); 4 } 5 }
标签:背包,int,max,完全,内存,一维 From: https://www.cnblogs.com/DLSQS-lkjh/p/17591548.html