HDU 2191 mourns the victims of the 512 Wenchuan earthquake-Cherish the present and be grateful for your life (multiple backpacks)

Source: Internet
Author: User
# Include <iostream> # include <cstdio> # include <algorithm>/* although this question cannot be sorted, however, I think it is more reasonable to buy the largest price and weight first */# include <cstring> # include <string> using namespace STD; # define n 105int DP [N]; struct node {int P, h, C;} num [105]; bool CMP (node A, Node B) {return. H * B. p>. p * B. h;} int main (void) {int n, m; int I, j, k; int C; CIN> C; while (c --) {CIN> N> m; for (I = 1; I <= m; I ++) CIN> num [I]. p> num [I]. h> num [I]. c; sort (Num + 1, num + m + 1, CMP); memset (DP, 0, sizeof (DP); for (I = 1; I <= m; I ++) for (k = 1; k <= num [I]. c; k ++) {for (j = N; j> = num [I]. p; j --) {DP [J] = max (DP [J], DP [J-num [I]. p] + num [I]. h) ;}} cout <DP [N] <Endl ;}return 0 ;}

 

HDU 2191 mourns the victims of the 512 Wenchuan earthquake-Cherish the present and be grateful for your life (multiple backpacks)

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.