给白瀚嵩
#include<bits/stdc++.h>
using namespace std;
const int N = 1e4+10;
int dp[N],w[N],v[N],s[N];
int main()
{
int n,m; cin >> n >> m;
for(int i = 1; i <= n; i++){
int a,b,c; cin >> a >> b >> c;
if(c == 0) c = m/a+1;
if(c == -1) c = 1;
int k = 1;
while(k <= c){
s[c]++;
w[s[c]] = k*a;
v[s[c]] = k*b;
c -= k;
k *= 2;
}
if(c > 0){
s[c]++;
w[s[c]] = k*c;
v[s[c]] = k*c;
}
}
for(int i = 1; i <= n; i++){
for(int j = M; J >= 0; j--){
for(int k = 0; k <= s[i] && k*w[i] <= j; k++) dp[j] = max(dp[j],dp[j-k*w[i]]+k*v[i]);
}
}
cout << dp[m] << endl;
return 0;
}