Maximum reimbursement amount
Time Limit: 1000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 16644 accepted submission (s): 4858
Problem description an existing fund can be reimbursed for a certain amount of invoices. 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.
The input 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 outputs one line for each test case, that is, the maximum amount that can be reimbursed, accurate to 2 digits after the decimal point.
Sample input200.00 32 A: 23.50 B: 100.001 C: 650.003 A: 59.99 A: 120.00 X: 10.000000.00 22 B: 600.00 A: 400.001 C: 200.502.16.50 32 B: 600.00 A: 400.001 C: 200.501 A: 100.00100.00 0
Sample output123.50 1000.00 1200.50 train of thought: This question was okay at the beginning, but 01 was added to the backpack for processing, and the format of the sample was a bit distressing to me, I am deeply impressed that the string is not refined (T. T ).... First, the maximum reimbursement amount and the number of invoices are given. Next there are n invoices. Each invoice first shows the number of items on the invoice, and then the price of each item and item.
Note: 1. Only items A, B, and C can be reimbursed. invoices containing other items will be voided.
2. The value of Danyang products cannot exceed 600
3. The total value of each invoice cannot exceed 1000
Maximum output value
Train of Thought: it's also a question of "01" backpack. It's not difficult to write it after knowing the conditions for appeal.
Code: # include <iostream># Include <algorithm>
#include <string.h>using namespace std;int dp[6000050];int main(){ char str; double Q,dj; int N,i,j,k,a,b,c; int money[35]; int sum=0,count=0;//赋初值 while(~scanf("%lf %d",&Q,&N) && N!=0 ) { int l=0; sum=(int)(Q*100);//如果用浮点数进行计算会产生误差,转化为一个类型计算 memset(money,0,sizeof(money)); memset(dp,0,sizeof(dp)); for(i=0;i<N;i++) { int flag=1;//用来判断是否是ABC三种类型,如果是则flag=1,else=0 scanf("%d",&k); a=b=c=0;//每种类型的物品价值赋初始值 while(k--) { scanf(" %c:%lf",&str,&dj); count=(int)(dj*100); if(str==‘A‘ && a+count<=60000) a+=count; else if(str==‘B‘ && b+count<=60000) b+=count; else if(str==‘C‘ && c+count<=60000) c+=count; else flag=0;//其他不是ABC的则不进行计算 } if(flag!=0 && a+b+c<=100000 && a<=60000 && b<=60000 && c<=60000)//判断价值是否超出规定价值
money[l++]=a+b+c; } for(i=0;i<=l;i++) { for(j=sum ; j>=money[i] ; j--) if(dp[j-money[i]]+money[i]>dp[j]) dp[j]=dp[j-money[i]]+money[i]; } printf("%.2lf\n",dp[sum]/100.0); } return 0;}
HDU 1864 Max reimbursement amount (01 backpack)