Files
lanqiao/00lanqiao chap/test100-1-6.cpp

29 lines
768 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// lanqiao 1176 4059 新一的宝藏搜寻加强版(多重背包优化)
#include <bits/stdc++.h>
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减ks最后可能还有点剩余也需要考虑上
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
*/