Title Description Description
The backpack volume is V, gives n items, each item occupies a volume of VI, the value of WI, each item can take up to 1 pieces, or the maximum number of MI pieces (Mi > 1), or the amount of unlimited, in the total volume of the items installed under the premise of the contents of the value of the goods and the largest value of what.
Enter a description input Description
The first line two number n,v, the following n lines each row three number Vi,wi,mi represents each item's volume, the value and the quantity, Mi=1 represents the most takes one piece, mi>1 indicates to take the Mi piece, the mi=-1 indicates the quantity infinite
Outputs description Output Description
1 Number ans indicates the maximum value of the loaded item value
Sample input to sample
2 10
3 7 2
2 4-1
Sample output Sample Outputs
22
Data Size & Hint
For 100% data, V <= 200000, N <= 200
State transfer According to the number of items
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace
Std
const int MAXN = 200005;
int n,v,x,vi,wi;
int ans = 0,DP[MAXN];
void Zopack (int vi,int WI) {for (int i = v-vi; I >= 0; I-) dp[i + VI] = MAX (dp[i + vi],dp[i] + WI);
Return
} void Wqpack (int vi,int WI) {for (int i = 0; I <= v-vi; i + +) Dp[i + vi] = MAX (dp[i + vi],dp[i] + WI);
Return
} void Dcpack (int vi,int wi,int x) {if (vi * x > V) wqpack (VI,WI);
int now = 1;
while (now < x) {Zopack (vi * NOW,WI * now);
X-= Now;
Now <<= 1;
} zopack (vi * X,WI * x);
Return
} int main () {scanf ("%d%d", &n,&v);
for (int i = 1; I <= n; i + +) {scanf ("%d%d%d", &vi,&wi,&x);
if (x < 0) wqpack (VI,WI);
else Dcpack (vi,wi,x);
} for (int i = 0; I <= v; i + +) ans = max (ans,dp[i]); printf ("%d\n", aNS);
return 0; }