Serie A championship: give the number of bones and the number of bags, then give each bone the price value and volume. Find bags to accommodate bone price values
Difficulty; This question is the most basic 01 backpack title, do not know, recommend to see "Backpack 9 Talk"
AC by SWS
Topic Link http://acm.hdu.edu.cn/showproblem.php?pid=2602
Code:
#include <stdio.h> #include <string.h>typedef struct{int W, v;} Str;str s[1005];int Dp[1005];int Main () {int n, m, T, I, J;SCANF ("%d", &t), while (T-) {scanf ("%d%d", &n, &m); fo R (i = 0; i < n; i + +) scanf ("%d", &S[I].W), for (i = 0; i < n; i + +) scanf ("%d", &S[I].V), memset (DP, 0, sizeof (d p)); for (i = 0, i < n; i + +) for (j = m; J >= S[i].v; J-) {if (DP[J]<DP[J-S[I].V] + s[i].w) dp[j] = Dp[j-s[i].v]+s[i ].W;} printf ("%d\n", Dp[m]);} return 0;}
Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.
Hdoj 2602 Bone Collector "01 Backpack"