HDU 2126 Buy The Souvenirs (01 backpack for total number of records)

Source: Internet
Author: User

Buy the Souvenirs

Time limit:10000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 1662 Accepted Submission (s): 611


Problem Descriptionwhen The winter holiday comes, a lot of people'll has a trip. Generally, there is a lot of souvenirs to sell, and sometimes the travelers would buy some ones with pleasure. Not only can they give the souvenirs to their friends and families as gifts, but also can the souvenirs leave them good re Collections. All in all, the prices of souvenirs is not very dear, and the souvenirs is also very lovable and interesting. The money the people has is under the control. They can ' t buy a lot, but only a few. So after they admire all the souvenirs, they decide to buy some ones, and they has many combinations to select, but there is no ones with the same kind in any combination. Now there are a blank written by the names and prices of the souvenirs, as a top coder all around the world, you should CAL Culate How many selections you has, and any selection owns the most kinds of different souvenirs. For instance:



And you had only $7, this time you can select any combination with 3 kinds of souvenirs for most, so the selections of 3 kinds of souvenirs are ABC (6), ABD (7). But if you had 8 RMB, the selections with the most kinds of souvenirs is ABC (6), ABD (7), ACD (8), and if you had ten R MB, there is only one selection with the most kinds of souvenirs to YOU:ABCD (10).

Inputfor the first line, there was a T means the number cases, then T cases follow.
In each case, in the first line there be, N and M, n is the number of the souvenirs and M was the money you hav E. The second line contains n integers; Each integer describes a kind of souvenir.
All the numbers and results is in the range of 32-signed Integer, and 0<=m<=500, 0<n<=30, t<=500, and the Prices is all positive integers. There is a blank line between the cases.

Outputif you can buy some souvenirs, your should print the result with the same formation as "you had s selection (s) to BU Y with K kind (s) of souvenirs ", where the K means the most kinds of souvenirs you can buy, and s means the numbers of the Combinations you can buy with the K kinds of souvenirs combination. But sometimes can buy nothing, so you must print the result "Sorry, you can ' t buy anything."

Sample Input24 71 2 3 4 4 01 2 3 4

Sample Outputyou has 2 selection (s) to buy with 3 kind (s) of souvenirs. Sorry, you can ' t buy anything.

Authorwangye

Sourcehdu 2007-10 Programming Contest

Recommend Whisky | We have carefully selected several similar problems for you:2128 2129 2130 2125 2124 record the total number of scenarios for 01 backpacks, add one dimension to the DP array, record the total number of scenarios, and remember that the initial All Dp[i][1] are set to 1. Test instructions: n items, M yuan, each item up to buy once, ask to buy a few items, and output the number of programs. Gayivi said he had bought several items. Attached code:
#include <iostream>#include<cstdio>#include<cstring>using namespacestd;intMain () {intt,n,m,i,j; inta[ *],dp[30s][2]; scanf ("%d",&T);  while(t--) {scanf ("%d%d",&n,&m);  for(i=0; i<n; i++) scanf ("%d",&A[i]); Memset (DP,0,sizeof(DP));  for(i=0; i<=m; i++) dp[i][1]=1;//Mark all 1 First, so many items, at least one option         for(i=0; i<n; i++)             for(j=m; j>=a[i]; j--)            {                if(dp[j][0]==dp[j-a[i]][0]+1)//If you record the number of items J yuan to take, it is exactly the same as the record at this time not to take the most items of this item plus 1dp[j][1]=dp[j-a[i]][1]+dp[j][1]; Else if(dp[j][0]<dp[j-a[i]][0]+1)//if it is less than, update the DP{dp[j][0]=dp[j-a[i]][0]+1; dp[j][1]=dp[j-a[i]][1]; }            }        if(dp[m][0]!=0) printf ("You have %d selection (s) to buy with%d kind (s) of souvenirs.\n", dp[m][1],dp[m][0]); Elseprintf ("Sorry, you can ' t buy anything.\n"); }    return 0;}

HDU 2126 Buy The Souvenirs (01 backpack for total number of records)

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.