lanqiao 1176 4059 新一的宝藏搜寻加强版(多重背包优化)
This commit is contained in:
28
00lanqiao chap/test100-1-6.cpp
Normal file
28
00lanqiao chap/test100-1-6.cpp
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
// 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);
|
||||||
|
}
|
||||||
|
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
|
||||||
|
*/
|
||||||
Reference in New Issue
Block a user