C++ 代码
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<sstream>
typedef long long ll;
using namespace std;
const double eps=1e-6;
const int inf=0x3f3f3f3f;
const int MAXN=1e2+7;
int N, V;
int v[MAXN], w[MAXN], s[MAXN];
int dp[MAXN];
int main(){
scanf("%d%d", &N, &V);
for(int i=1; i<=N; i++){
scanf("%d%d%d", &v[i], &w[i], &s[i]);
}
for(int i=1; i<=N; i++){
int min_num = min(s[i], V/v[i]);//最多可以装min_num个背包
for(int k = 1; min_num ; k<<=1){
if(k > min_num )
k = min_num;
min_num -= k;
for(int j=V; j>=k*v[i]; j--)
dp[j] = max(dp[j], dp[j-k*v[i]] + k*w[i]);
}
}
printf("%d\n", dp[V]);
return 0;
}
```