See also 01 backpack time limit: ms | Memory limit:65535 KB Difficulty:3
-
Describe
-
there are n weights and values for the items of WI and VI , from which the total weight of items not exceeding W is chosen, and the maximum value of the sum of the items in all selection options is obtained. 1 <= N <=100 1 <= wi <= 10^7 1 <= vi <= 1 <= W <= 10^9
-
-
Input
-
-
multiple sets of test data. Each set of test data is entered in the first row, N and W, followed by n lines, each line entered two numbers, representing the first item of WI and VI.
-
-
Output
-
-
meet the maximum value of test instructions, one row per group of test data.
-
-
Sample input
-
-
4 52 31 23 42 2
-
-
Sample output
-
-
7
-
-
Source
-
-
Drift Friendship Series
-
-
Uploaded by
-
-
tc_ Zhang Friendship
-
-
#include <stdio.h>#include<algorithm>using namespacestd;intdp[10001],wi[101],vi[101];Const intinf=0x6fffffff;//0x3f3f3f3f;//;intMain () {intn,w; while(~SCANF ("%d%d",&n,&W)) { intsum=0, I,v; for(i=1; i<=n;++i) {scanf ("%d%d",&wi[i],&Vi[i]); Sum+=Vi[i]; } for(i=1; i<=sum;++i) dp[i]=INF; dp[0]=0; for(i=1; i<=n;++i) { for(v=sum;v>=vi[i];--v) {Dp[v]=min (dp[v-vi[i]]+Wi[i],dp[v]); } } for(i=sum;i>=0;--i) { if(dp[i]<=W) Break; } printf ("%d\n", i); } return 0;}
NYOJ-860 See 01 Backpack again