Hdu1864_ maximum reimbursement amount (Backpack/01 backpack)

Source: Internet
Author: User
Tags uppercase letter

Solution report

Question Portal

#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define inf 99999999using namespace std;int v,w[35],d[4],dw1,sum,dp[31*1000*100];int main(){    double Q,dw;    int n,i,j,m,t;    char c;    while(~scanf("%lf %d",&Q,&n)) {        m=0;        v=(int)(Q*100);        memset(dp,0,sizeof(dp));        memset(w,0,sizeof(w));        if(!n)break;        for(i=1; i<=n; i++) {            scanf("%d",&t);            sum=0;            int f=0;            memset(d,0,sizeof(d));            for(j=1; j<=t; j++) {                scanf(" %c:%lf",&c,&dw);                dw1=(int)(dw*100);                if(c>='A'&&c<='C') {                    d[c-'A']+=dw1;                    sum+=dw1;                } else f=1;            }            if(!f&&sum<=100000&&d[0]<=60000&&d[1]<=60000&&d[2]<=60000) {                w[m++]=sum;            }        }        for(i=0; i<m; i++) {            for(j=v; j>=w[i]; j--) {                dp[j]=max(dp[j],dp[j-w[i]]+w[i]);            }        }        printf("%.2lf\n",dp[v]/100.0);    }}

Maximum reimbursement amount Time Limit: 1000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 16358 accepted submission (s): 4775


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 Input
200.00 32 A:23.50 B:100.001 C:650.003 A:59.99 A:120.00 X:10.001200.00 22 B:600.00 A:400.001 C:200.501200.50 32 B:600.00 A:400.001 C:200.501 A:100.00100.00 0

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.