Hdu1864_ maximum reimbursement amount [01 backpack]

Source: Internet
Author: User
Maximum reimbursement amount

Time Limit: 1000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/others) total submission (s): 16679 accepted submission (s): 4864
Problem description
An invoice with a certain amount of funds can be reimbursed. The types of invoices that can be reimbursed include books (Class A), stationery (Class B), and travel (Class C). The total amount of each invoice must not exceed 1000 RMB, the value of a single item cannot exceed 600 RMB. Please write a program to find out the maximum reimbursement amount that can be reimbursed and does not exceed the given quota in a pile of invoices.

Input
The test input contains several test cases. The first row of each test case contains two positive Q and n, where Q is the specified reimbursement quota and N (<= 30) is the invoice count. Followed by N rows of input, the format of each line is:
M type_1: price_1 type_2: price_2... type_m: price_m
The positive integer m is the number of items opened on the invoice, and type_ I and price_ I are the types and values of items I. The item type is represented by an uppercase letter. When N is 0, all input ends, and the corresponding results are not output.

Output
Output one line for each test case, that is, the maximum amount that can be reimbursed, accurate to 2 digits after the decimal point.

Sample Input
200.00 3
2 A: 23.50 B: 100.00
1 C: 650.00
3 A: 59.99 A: 120.00 X: 10.00
1200.00 2
2 B: 600.00 A: 400.00
1 C: 200.50
1200.50 3
2 B: 600.00 A: 400.00
1 C: 200.50
1 A: 100.00
100.00 0

Sample output
123.50
1000.00
1200.50
 
Source

Zhejiang University Computer postgraduate review computer examination-2007

I can basically understand it. I will give you n invoices, and only A, B, and C items on the invoice can be reimbursed,

In addition, an invoice can be reimbursed at most 1000 yuan, and each type of A, B, and C goods cannot exceed 600 yuan. I will pay you a sum of money,

Ask the maximum amount of reimbursement for the invoice that meets the reimbursement requirements.

Idea: if the price * 100 is converted into an integer, the reimbursement-compliant invoice can be used as an item, and the money can be used as the weight and value of the backpack,

Total capacity is charged. The maximum amount of money can be reimbursed.

# Include <stdio. h> # include <string. h> # include <algorithm> using namespace STD; int money [40]; int DP [3000010]; // The array size is 1000*30*100 = 300366int main () {double Q, price; char type; int n, m; while (~ Scanf ("% lf % d", & Q, & N) & n! = 0) {memset (money, 0, sizeof (money); For (INT I = 0; I <n; I ++) {int flag = 0; int, b, C; a = B = C = 0; scanf ("% d", & M); For (Int J = 0; j <m; j ++) {getchar (); scanf ("% C: % lf", & type, & price); // scanf ("% * C % C: % lf", & type, & price); int t = (INT) (price * 100); If (type = 'A') {A + = T ;} else if (type = 'B') {B + = T;} else if (type = 'C') {C + = T;} else {flag = 1; // items except items A, B, and C} If (flag = 0 & A <= 60000 & B <= 60000 & C <= 60000 & & A + B + C <= 100000) {money [I] = A + B + C;} else {money [I] = (INT) (Q * 100) + 1 ;}} memset (DP, 0, sizeof (DP); For (INT I = 0; I <n; I ++) {for (Int J = (INT) (Q * 100 ); j> = money [I]; j --) {DP [J] = max (DP [J], DP [J-money [I] + money [I]) ;}} printf ("%. 2lf \ n ", DP [(INT) (Q * 100)]/100.0);} return 0 ;}


Hdu1864_ maximum reimbursement amount [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.