Hdu1865 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): 7437 accepted submission (s): 1797


Problem description

A certain amount of invoices can be reimbursed. The types of invoices that can be reimbursed include
Class), stationery (B
Class), travel (C
Class), 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. 1st of each test case.
The row contains two positive numbers Q
And n
, Where Q
Is the specified reimbursement amount, n
(<= 30
) Is the number of invoices. Followed by N
Line input. The format of each line is:
M type_1: price_1 type_2: price_2... type_m: price_m

Positive integer m
Is the number of items opened on this invoice, type_ I
And price_ I
Yes I
Item category and value. The item type is represented by an uppercase letter. When N
0
When all input ends, the corresponding results are not output.

 

 

Output

Output 1 for each test case
Line, that is, the maximum amount of reimbursement, accurate to 2 after the decimal point
Bit.

 

 

Sample Input

200.00 3

2
23.50
B: 100.00

1 c
650.00

3
: 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
100.00

100.00 0

 

 

Sample output

123.50

1000.00

1200.50

 

 

01
Backpack
,
Not much explanation

 

# Include <stdio. h> <br/> # include <string. h> <br/> int DP [10000005]; <br/> bool mark [35]; <br/> int N, I, j, M, PP, TMP, total; <br/> double TT, P; <br/> char C; <br/> struct P <br/>{< br/> int P [3], all; <br/>} price [35]; <br/> int max (int A, int B) <br/>{< br/> return A> B? A: B; <br/>}< br/> void Init () <br/>{< br/> int I; <br/> memset (mark, 0, sizeof (Mark); <br/> total = TT * 100.0; <br/> for (I = 0; I <= total; ++ I) DP [I] = 0; <br/> for (I = 1; I <= N; ++ I) <br/>{< br/> memset (price [I]. p, 0, sizeof (price [N]. p); <br/> price [I]. all = 0; <br/>}< br/> int main () <br/>{< br/> while (scanf ("% lf % d", & TT, & n )) <br/>{< br/> If (n = 0) break; <br/> Init (); <br/> for (I = 1; I <= N; ++ I) <br/> {<br /> Scanf ("% d", & M); <br/> for (j = 1; j <= m; ++ J) <br/>{< br/> scanf ("% C: % lf", & C, & P); <br/> PP = p * 100.0; <br/> If (C = 'A' | C = 'B' | C = 'C ') <br/>{< br/> price [I]. P [C-'a'] + = pp; <br/> If (price [I]. P [C-'a']> 60000) MARK [I] = 1; <br/>}< br/> else mark [I] = 1; <br/>}< br/> price [I]. all = Price [I]. P [0] + price [I]. P [1] + price [I]. P [2]; <br/> If (price [I]. all> 100000) MARK [I] = 1; <br/>}< br/> for (I = 1; I <= N; ++ I) <br/> {<Br/> If (! Mark [I]) <br/>{< br/> for (j = total; j> = Price [I]. all; -- j) <br/>{< br/> DP [J] = max (DP [J], DP [J-price [I]. all] + price [I]. all); <br/>}< br/> printf ("%. 2lf/N ", double (DP [total])/100); <br/>}< br/> return 0; <br/>}< br/>

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.