Maximum Reimbursement Amount
Time limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 21113 Accepted Submission (s): 6326
Problem description A certain amount of invoices can be reimbursed for the existing funds. 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.
The input test inputs contain 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 (<=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 outputs 1 rows per test case, which is the maximum amount that can be reimbursed, and is accurate to 2 digits after the decimal point.
Sample Input200.00 a:23.50 b:100.001 c:650.003 a:59.99 a:120.00 x:10.001200.00 32 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 Output123.501000.001200.50
Source Zhejiang University computer Graduate Exam-2007:01 Backpack ... The input is disgusting, and many places need to be aware of the value to be converted into integers. So take 100, so the space to open to 30*1000*100, just here re n times. Then not every item is greater than 600, but the value of A's total value suma<=600 (B,c also). This place WA n times. After the input processing is 01 knapsack water problem ... *_*
#include <stdio.h>#include<algorithm>#include<string.h>#include<iostream>#include<math.h>#defineM 3000050///30*1000*100using namespacestd;DoubleQ;intN;intDp[m];intw[ -];intK;voidinput () {intm; for(intI=1; i<=n; i++) {scanf ("%d",&m); CharC; DoublePrice ; intsum =0, suma=0, sumb=0, sumc=0; intFlag =1; for(intj=1; j<=m; J + +) {scanf ("%C:%LF",&c,&Price ); intv = (int) (price* -); //printf ("%d%d%d%d\n", V,SUMA,SUMB,SUMC); if(c=='A'&& suma+v<=60000) {///single and cannot exceedsuma+=v; } Else if(c=='B'&&sumb+v<=60000) {Sumb+=v; } Else if(c=='C'&&sumc+v<=60000) {SUMC+=v; }ElseFlag =0; } if(flag&&suma+sumb+sumc<=100000) { //printf ("%d%d%d\n", SUMA,SUMB,SUMC);W[k] = suma+sumb+SUMC; //printf ("%d\n", W[k]);k++; }} k--; /*for (int i=1;i<=k;i++) {printf ("%d\n", W[i]); }*/}intMain () { while(SCANF ("%lf%d", &q,&n)! =eof,n) {k=1; intQ1 = (int) (q* -); Input (); Memset (DP,0,sizeof(DP)); for(intI=1; i<=k;i++){ for(intv=q1;v>=w[i];v--) {Dp[v]= Max (dp[v],dp[v-w[i]]+V[i]); }} printf ("%.2lf\n", dp[q1]*1.0/ -); } return 0;}
Hdu 1864 (01 backpack, input processing really annoying)