加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

01背包(容量为浮点数)

发布时间:2020-12-13 21:25:14 所属栏目:PHP教程 来源:网络整理
导读:http://acm.hdu.edu.cn/showproblem.php?pid=1864 最大报销额 Time Limit: 1000/1000 MS (Java/Others)????Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 36208????Accepted Submission(s): 11135 Problem Description 现有一笔经费可以

http://acm.hdu.edu.cn/showproblem.php?pid=1864

最大报销额

Time Limit: 1000/1000 MS (Java/Others)????Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 36208????Accepted Submission(s): 11135


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
浙大计算机研究生复试上机考试-2007年
?

?

Recommend
lcy???|???We have carefully selected several similar problems for you:?? 1231? 1087? 2844? 2159? 1505
//#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <stdio.h>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string.h>
#include <vector>
#define ME(x,y) memset(x,y,sizeof(x))
#define SF(n) scanf("%d",&n)
#define rep(i,n) for(int i = 0 ; i < n ; i ++)
#define INF  0x3f3f3f3f
#define mod 1000000007
#define PI acos(-1)
using namespace std;
typedef long long ll ;
int dp[3000009],w[30];

int main()
{
    double  n ;
    double v ;
    while(~scanf("%lf%lf",&v,&n) && n)
    {
        int flag ;
        memset(w,0,sizeof(w));
        memset(dp,sizeof(dp));

        for(int i = 1 ; i <= n ; i++)
        {
            int num ;
            scanf("%d",&num);
            flag = 1 ;
            int x,z ;
            x = y = z = 0 ;
            for(int j = 1 ; j <= num ; j++)
            {
                double val ;
                char c,d;
                cin >> c >> d >> val ;
                val = val * 100 ;
                if(c == A && x + val <= 60000)
                {
                    x += val ;
                }
                else if(c == B && y + val <= 60000)
                {
                    y += val ;
                }
                else if(c == C && z + val <= 60000)
                {
                    z += val ;
                }
                else
                {
                    flag = 0 ;
                }
            }
            if(x + y + z <= 100000 && flag)
                    w[i] = x + y + z ;
        }
        int vv = v * 100 ;
        for(int i = 1 ; i <= n ; i++)
        {
            for(int j = vv ; j >= w[i] ; j--)
            {
                dp[j] = max(dp[j],dp[j-w[i]]+w[i]);
            }
        }
        printf("%.2lfn",(double)dp[vv]/100);

    }

    return 0;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读