-
Title Description:
-
a certain amount of invoices can be reimbursed for an existing provision. The types of invoices that are allowed to be reimbursed include buying books (Class A), stationery (category B), travel (class C), requiring that the total amount of each invoice not exceed $1000, and the value of individual items on each invoice shall not exceed 600 yuan. You are now asked to write a procedure to find out the maximum amount of reimbursement that can be reimbursed, not exceeding a given amount, in a given pile of invoices.
-
Input:
-
The test input contains several test cases. The 1th line of each test case contains two positive numbers q and N, where Q is the given reimbursement amount, and N (n<=30) is the number of invoice sheets. followed by the N-line input, with the format of each line:
M type_1:price_1 type_2:price_2 ... Type_m:price_m
Where the positive integer m is the number of items opened on this invoice, type_i and Price_i are the categories and values of item I. The item type is indicated by an uppercase English letter. When n is 0 o'clock, all input ends and the corresponding result is not output.
-
Output:
-
Output 1 rows for each test case, which is the maximum amount that can be reimbursed, accurate to 2 digits after the decimal point.
-
Sample input:
-
200.00 a:23.50 b:100.001 c:650.003 a:59.99 a:120.00 x:10.001200.00 all b:600.00 a:400.001 c:200.501200.50 + B:600.00 A: 400.001 c:200.501 a:100.00100.00 0
-
-
Sample output:
-
123.501000.001200.50
Idea: Reimbursement for the invoice as a unit, with deep search to achieve 01 backpack
#include <cstdio>#include<cstring>#include<algorithm>using namespacestd;structnode{Doublesum; BOOLMark;} order[ *];Doublelimit;intN;DoubleRes;voidDfsintIDoubles) { if(i==N) {if(s<=limit) Res=Max (res,s); return ; } if(Order[i].mark) {DFS (i+1, s+order[i].sum); DFS (i+1, s); } Else{DFS (i+1, s); }}intMain () { while(SCANF ("%lf%d", &limit,&n)!=eof&&n!=0) {res=0; for(intI=0;i< *; i++) {order[i].sum=0.0; Order[i].mark=true; } for(intI=0; i<n;i++) { intm; scanf ("%d",&m); Charop; DoublePrice ; for(intj=0; j<m;j++) {scanf ("%*C%C%*C%LF",&op,&Price ); if(op!='A'&&op!='B'&&op!='C') {Order[i].mark=false; } Else { if(Order[i].mark) {order[i].sum+=Price ; } }}} DFS (0,0); printf ("%.2lf\n", RES); } return 0;}
2007 Zhejiang University: Maximum Reimbursement amount