maximum reimbursement
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 25076 Accepted Submission(s): 7716
Problem Description
Existing funds can be reimbursed for a certain amount of invoices. The types of invoices that are allowed to be reimbursed include buying books ( Type A), stationery (Type B), and business trips (Type C). . Now please write a program to find out the maximum reimbursement amount that can be reimbursed within a given amount of invoices.
Input
Test input contains several test cases. Line 1 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 invoices. Followed by N lines of input, the format of each line is:
m Type_1:price_1 Type_2:price_2 ... Type_m:price_m
where the positive integer m is the number of items issued on this invoice, and Type_i and price_i are the types of the item i and value. The item type is represented by a capital letter. When N is 0, all input ends, and the corresponding result is not output.
Output
Output 1 line for each test case , the maximum amount that can be reimbursed, accurate to 2 decimal places.
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
#include <stdio.h> #include <algorithm> #include <string.h> using namespace std; int dp[3000050]; intmain() { char ch; double x,y; int sum,a,b,c,money[35],v; int t,i,j,k; while(~scanf("%lf%d",&x,&t),t) { sum = (int)(x*100);//Convert decimals to integers memset(money,0,sizeof(money)); memset(dp,0,sizeof(dp)); int l = 0; for(i = 0; i<t; i++) { scanf("%d",&k); a = b = c = 0; int flag = 1; while(k--) { scanf(" %c:%lf",&ch,&y); v = (int)(y*100); if(ch == 'A' && a+v<=60000) a+=v; else if(ch == 'B' && b+v<=60000) b+=v; else if(ch == 'C' && c+v<=60000) c+=v; else flag = 0; } if(a+b+c<=100000 && a<=60000 && b<=60000 && c<=60000 && flag)//According to the meaning of the title, these conditions must be met money[l++] = a+b+c ; } for(i = 0; i<=l; i++) { for(j = sum; j>=money[i]; j--) dp[j] = max(dp[j],dp[j-money[i]]+money[i]); } printf("%.2lf\n",dp[sum]/100.0); } return 0; }