#include<bits/stdc++.h>
#define int long long
using namespace std;
int T,n,W;
int w[100005],v[100005],s[100005];
int f[100005];//99000
signed main(){
cin>>n>>W;
int cnt=0;
for(int i=1,w1,v1,s1;i<=n;i++){
cin>>v1>>w1>>s1;
int p=0;
while(1){
if(s1-(1ll<<p)>=0){
s1-=(1ll<<p);
w[++cnt]=w1*(1ll<<p);
v[cnt]=v1*(1ll<<p);
}else break;
p++;
}
if(s1>0){
w[++cnt]=w1*s1;
v[cnt]=v1*s1;
}
}
for(int i=1;i<=cnt;i++){
for(int j=W;j>=w[i];j--){
f[j]=max(f[j],f[j-w[i]]+v[i]);
}
}
cout<<f[W]<<endl;
return 0;
}多重背包二进制优化
文章信息与版本
文章信息
- 发布
- 2024年1月5日
- 收录
- 2025年12月12日
- 更新
- 2026年11月13日
- 篇幅
- 约 1 分钟