zoukankan      html  css  js  c++  java
  • HDU 1864

    最大报销额

    Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 19511    Accepted Submission(s): 5779


    Problem Description
    现有一笔经费可以报销一定额度的发票。允许报销的发票类型包括买图书(A类)、文具(B类)、差旅(C类),要求每张发票的总额不得超过1000元,每张发票上,单项物品的价值不得超过600元。现请你编写程序,在给出的一堆发票中找出可以报销的、不超过给定额度的最大报销额。
     
    Input
    测试输入包含若干测试用例。每个测试用例的第1行包含两个正数 Q 和 N,其中 Q 是给定的报销额度,N(<=30)是发票张数。随后是 N 行输入,每行的格式为:
    m Type_1:price_1 Type_2:price_2 ... Type_m:price_m
    其中正整数 m 是这张发票上所开物品的件数,Type_i 和 price_i 是第 i 项物品的种类和价值。物品种类用一个大写英文字母表示。当N为0时,全部输入结束,相应的结果不要输出。
     
    Output
    对每个测试用例输出1行,即可以报销的最大数额,精确到小数点后2位。
     
    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
     
    Source
     
    Recommend
    lcy   |   We have carefully selected several similar problems for you:  1203 1231 1087 2844 2159 
     
    开始理解错了题意,预处理完了就是裸01背包,中文题意我都没理解,简直了~~~
    #include <cstdio>
    #include <iostream>
    #include <sstream>
    #include <cmath>
    #include <cstring>
    #include <cstdlib>
    #include <string>
    #include <vector>
    #include <map>
    #include <set>
    #include <queue>
    #include <stack>
    #include <algorithm>
    using namespace std;
    #define ll long long
    #define _cle(m, a) memset(m, a, sizeof(m))
    #define repu(i, a, b) for(int i = a; i < b; i++)
    #define repd(i, a, b) for(int i = b; i >= a; i--)
    #define sfi(n) scanf("%d", &n)
    #define sfl(n) scanf("%I64d", &n)
    #define pfi(n) printf("%d
    ", n)
    #define pfl(n) printf("%I64d
    ", n)
    #define MAXN 35
    char s[105];
    double dp[3000005];
    double bill[MAXN];
    int main()
    {
        double q, p;
        int n;
        while(~scanf("%lf%d", &q, &n) && n)
        {
            q = q * 100.0;
            int Q = q, m, flag, num;
            char C;
            double a, b, c;
            repu(i, 0, n)
            {
                flag = 0;
                sfi(m);
                a = b = c = 0.0;
                repu(j, 0, m)
                {
                    scanf("%s", s);
                    sscanf(s, "%c:%lf", &C, &p);
                    if(C == 'A') a += p;
                    else if(C == 'B') b += p;
                    else if(C == 'C') c += p;
                    else flag = 1;
                }
                if(!flag && a + b + c <= 1000.0 && a <= 600.0 && b <= 600.0 && c <= 600.0)
                        bill[num++] = (a + b + c) * 100.0;
            }
            _cle(dp, 0);
            repu(i, 0, num)
                for(int j = Q; j >= (int)bill[i]; j--)
                    dp[j] = max(dp[j], dp[j - (int)bill[i]] + bill[i]);
            printf("%0.2lf
    ", dp[Q] / 100.0);
        }
        return 0;
    }
    View Code
  • 相关阅读:
    LeetCode 43. 字符串相乘(Multiply Strings)
    LeetCode 541. 反转字符串 II(Reverse String II)
    枚举类型
    c#字母加密
    汇率兑换Python
    冒泡排序c#
    c#
    HTML
    日历
    Java2
  • 原文地址:https://www.cnblogs.com/sunus/p/4738805.html
Copyright © 2011-2022 走看看