Hdoj 2602 Bone Collector "01 Backpack"

Source: Internet
Author: User

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"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.