Mourning for 512 Wenchuan earthquake--cherish now, Thanksgiving life hdu2191 (01 backpack)

Source: Internet
Author: User

http://acm.hdu.edu.cn/showproblem.php?pid=2191

Chinese topic, do not say nonsense ...

Analysis: The problem is a multi-pack, but can be used 01 backpack to do, each kind of rice has a few bags a separate storage, so it becomes 01 backpack ...

#include <iostream>#include<stdio.h>#include<string.h>#include<string>#include<vector>#include<algorithm>#include<map>#include<queue>#include<stack>#include<math.h>using namespacestd;#defineMet (A, b) memset (A, B, sizeof (a))#defineMAXN 2500#defineINF 0x3f3f3f3fConst intMOD = 1e9+7; typedefLong LongLL;intDP[MAXN];structnode{intx, y;} S[MAXN];intMain () {intT, N, M, p, H, C; scanf ("%d", &T);  while(T--) {scanf ("%d%d", &n, &m); intK =1;  for(intI=1; i<=m; i++) {scanf (" %d%d%d", &p, &h, &c);  for(intj=1; j<=c; J + +) {s[k].x=p; S[k++].y=h; }} memset (DP,0,sizeof(DP));  for(intI=1; i<k; i++)        {             for(intJ=n; j>=s[i].x; j--) {Dp[j]= Max (Dp[j], dp[j-s[i].x]+s[i].y); }} printf ("%d\n", Dp[n]); }    return 0;}
View Code

Mourning for 512 Wenchuan earthquake--cherish now, Thanksgiving life hdu2191 (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.