// lanqiao 1176 4059 新一的宝藏搜寻加强版(多重背包优化) #include using namespace std; #define endl '\n' const int N = 2e4+10; int dp[N]; int main(){ // 请在此输入您的代码 ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); int n, m; cin >> n >> m; for(int i = 1; i <= n; i++){ int w, v, s; cin >> w >> v >> s; // 体积、价值、数量 for(int k = 1; k <= s; s -= k, k += k){ for(int j = m; j >= k * w; j--) dp[j] = max(dp[j], dp[j - k*w] + k*v); } // s减k,s最后可能还有点剩余,也需要考虑上 for(int j = m; j >= s * w; j--) dp[j] = max(dp[j], dp[j - s*w] + s*v); } cout << dp[m] << endl; return 0; } /* test samples -> 40 5 20 20 16 4 2 4 16 10 18 6 18 14 14 18 17 5 */