HDU-1864-最大报销额

链接:https://vjudge.net/problem/HDU-1864#author=0

题意:

现有一笔经费可以报销一定额度的发票。允许报销的发票类型包括买图书(A类)、文具(B类)、差旅(C类),要求每张发票的总额不得超过1000元,每张发票上,单项物品的价值不得超过600元。现请你编写程序,在给出的一堆发票中找出可以报销的、不超过给定额度的最大报销额。 

思路:

先处理输入,出现不能报销的种类直接不加入A数组。

同时注意,发票上的单个种类可能分多次显示。

同时将值乘100用来去除小数。

代码:

#include <iostream>
#include <memory.h>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdio>
#include <math.h>

using namespace std;

typedef long long LL;

const int MAXN = 30 + 10;

int dp[MAXN * 1000 * 100];
int A[MAXN];

int main()
{
    double q;
    int v, n;
    while (~scanf("%lf%d", &q, &n))
    {
        memset(dp, 0, sizeof(dp));
        if (!n)
            break;
        v = (int)(q * 100);
        int cnt = 0;
        for (int i = 1;i <= n;i++)
        {
            int t;
            int a, b, c;
            a = b = c = 0;
            double cost;
            char type;
            int flag = 1;
            scanf("%d", &t);
            for (int j = 1;j <= t;j++)
            {
                scanf(" %c:%lf", &type, &cost);
                if (type != 'A' && type != 'B' && type != 'C')
                    flag = 0;
                if (type == 'A')
                    a += (int)(cost * 100);
                if (type == 'B')
                    b += (int)(cost * 100);
                if (type == 'C')
                    c += (int)(cost * 100);
            }
            if (a + b + c > 1000 * 100)
                flag = 0;
            if (a > 600 * 100 || b > 600 * 100 || c > 600 * 100)
                flag = 0;
            if (flag)
                A[++cnt] = a + b + c;
        }

        for (int i = 1;i <= cnt;i++)
        {
            for (int j = v;j >= A[i];j--)
                dp[j] = max(dp[j], dp[j - A[i]] + A[i]);
        }
        printf("%.2lf\n", dp[v] / 100.0);

    }


    return 0;
}

  

posted @ 2019-03-03 14:27  YDDDD  阅读(172)  评论(0编辑  收藏  举报