HDU 1864 Maximum Reimbursement amount DP

Source: Internet
Author: User

Maximum Reimbursement AmountTime limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 17244 Accepted Submission (s): 5046


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 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


#include <iostream> #include <cstring> #include <cstdio>using namespace Std;int v[35],dp[3000000+5];    int main () {double p,n;        while (Cin>>p>>n && N) {p*=100;        int I,j,m,a,b,c,flag;            for (i=1;i<=n;i++) {double p;            Char ch,cc;            cin>>m;            a=b=c=flag=0;                for (j=1;j<=m;j++) {scanf ("%c%c:%lf", &cc,&ch,&p);                p*=100;                if (ch== ' A ') a+=p;                else if (ch== ' B ') b+=p;                else if (ch== ' C ') c+=p;            else flag=1;                } if (!flag&&a+b+c<=100000&&a<=60000&&b<=60000&&c<=60000)            V[i]=a+b+c;        else v[i]=p+1;        } memset (dp,0,sizeof DP);        for (i=1;i<=n;i++) for (j=p;j>=v[i];j--) Dp[j]=max (Dp[j],dp[j-v[i]]+v[i]);    printf ("%.2lf\n", dp[(int) p]/100.0); } return 0;}


HDU 1864 Maximum Reimbursement amount DP

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.