ConsumerTime
limit:4000/2000 MS (java/others) Memory limit:32768/65536 K (java/others)
Total submission (s): 1435 Accepted Submission (s): 752
Problem DESCRIPTIONFJ is going to does some shopping, and before that, he needs some boxes to carry the different kinds of s Tuff He is going to buy. Each box was assigned to carry some specific kinds of stuff (that's to say, if he was going to buy one of these stuff, he h As to buy the box beforehand). Each kind of stuff have its own value. Now FJ only have an amount of W dollars for shopping, he intends to get the highest value with the money.
Inputthe first line would contain the integers, n (the number of boxes 1 <= n <=), W (the amount of money FJ have, 1 <= w <= 100000) then n lines follow. Each line contains the following number pi (the price of the ith box 1<=pi<=1000), MI (1<=mi<=10 the number go ODS ith box can carry), and mi pairs of numbers, the price CJ (1<=cj<=100), the value VJ (1<=vj<=1000000)
Outputfor each test case, output the maximum value FJ can get
Sample Input
3 800300 2 30 50 25 80600 1 50 130400 3 40 70 30 40 35 60
Sample Output
210
Source2010 acm-icpc multi-university Training Contest (2)--host by Bupt
Recommendwe carefully selected several similar problems for you:3535 2415 3443 3450 3448
Each group of items added to the box limit, if you want to buy the reorganization of items, you must first buy the box
When considering the items in group I, the optimal value of the former I-1 group is known, assuming the total capacity is V, the cost of the restructured box is p, so if we want to buy the group of items, the usable capacity is only v-p, so we first use the TMP array to record the first i-1 stage capacity range in the range of [0,v-p] the optimal value, corresponding to the cost of the box P [p,v] this interval, and then within this range to reorganize items to do 01 backpack, and then to update the DP value
AC Code
#include <stdio.h> #include <string.h> #define MAX (A, B) (A>B?A:B) __int64 dp[100010],n,m,temp[100010]; int main () {while (scanf ("%i64d%i64d", &n,&m)!=eof) {int I,j,k,vv,cnt;memset (dp,0,sizeof (DP)); for (i=0;i<n ; i++) {scanf ("%d%d", &vv,&cnt); for (j=0;j+vv<=m;j++) {temp[j+vv]=dp[j];} for (j=1;j<=cnt;j++) {int w,v;scanf ("%d%d", &w,&v); for (k=m;k>=w+vv;k--) Temp[k]=max (Temp[k],temp[k-w] +V);} for (j=vv;j<=m;j++) Dp[j]=max (Dp[j],temp[j]);} printf ("%i64d\n", Dp[m]);}}
Hdoj topic 3449 Consumer (backpack)