Hdu acm 2191 mourns the victims of the 512 Wenchuan earthquake-Cherish the present and live a grateful life

Source: Internet
Author: User

Question link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 2191

There are capital N and M types of rice, for the I type of rice, the price, quantity, number of bags are: PI, hi, CI, ask the maximum weight of rice that can be purchased.

Start with multiple backpacks ~~~~~~

In the 01 backpack, there is a heavy loop between the two duplicates. 0 ~ Bag [I]: indicates the number of items in Type I ranges from 0 ~ Bag [I] enumeration.

1 # include <iostream> 2 # include <cstring> 3 # include <cstdio> 4 using namespace STD; 5 6 const int maxn = 200 + 5; 7 8 int W [maxn], V [maxn], num [maxn]; 9 int DP [maxn]; 10 11 int main () 12 {13 int T, money, kind; 14 While (scanf ("% d", & T )! = EOF) 15 {16 while (t --) 17 {18 scanf ("% d", & money, & kind); 19 for (INT I = 0; I <kind; I ++) 20 scanf ("% d", & V [I], & W [I], & num [I]); 21 memset (DP, 0, sizeof (DP); 22 for (INT I = 0; I <kind; I ++) 23 {24 for (Int J = 0; j <num [I]; j ++) // This loop is added !!! 25 {26 for (int K = money; k> = V [I]; k --) 27 DP [k] = max (DP [K], DP [k-V [I] + W [I]); 28} 29} 30 printf ("% d \ n", DP [money]); 31} 32} 33 return 0; 34}

 

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.