for (int i = 1; i <= n; i ++) cin >> v[i] >> w[i] >> s[i];
for (int i = 1; i <= n; i ++) for (int j = 0; j <= m; j ++) for (int k = 0; k <= s[i] && k * v[i] <= j; k ++) dp[i][j] = max(dp[i][j], dp[i - 1][j - k * v[i]] + k * w[i]);
int cnt = 0; // 将所有物品重新打包分组 for (int i = 1; i <= n; i ++) { int a, b, s; cin >> a >> b >> s; int k = 1; while (k <= s) { cnt ++; v[cnt] = a * k; w[cnt] = b * k; s -= k; k *= 2; } if (s) { cnt ++; v[cnt] = a * s; w[cnt] = b * s; } }
n = cnt; // 变成了01背包问题 for (int i = 1; i <= n; i ++) for (int j = m; j >= v[i]; j --) dp[j] = max(dp[j], dp[j - v[i]] + w[i]);