hdu 5445 多重背包
Food Problem
Time Limit: 3000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1243 Accepted Submission(s): 368
Other than obtaining the desserts, Bell also needs to consider moving them to the game arena. Different trucks may carry different amounts of desserts in size and of course they have different costs. However, you may split a single dessert into several parts and put them on different trucks, then assemble the parts at the game arena. Note that a dessert does not provide any energy if some part of it is missing.
Bell wants to know how much would it cost at least to provide desserts of a total energy of p (most of the desserts are not bought with money, so we assume obtaining the desserts costs no money, only the cost of transportation should be considered). Unfortunately the mathematician is having trouble with her stomach, so this problem is left to you.
For each test case there are three integers n,m,p on the first line (1≤n≤200,1≤m≤200,0≤p≤50000), representing the number of different desserts, the number of different trucks and the least energy required respectively.
The i−th of the n following lines contains three integers ti,ui,vi(1≤ti≤100,1≤ui≤100,1≤vi≤100) indicating that the i−th dessert can provide tienergy, takes up space of size ui and that Bell can prepare at most vi of them.
On each of the next m lines, there are also three integers xj,yj,zj(1≤xj≤100,1≤yj≤100,1≤zj≤100) indicating that the j−th truck can carry at most size of xj , hiring each one costs yj and that Bell can hire at most zj of them.
1 1 7
14 2 1
1 2 2
1 1 10
10 10 1
5 7 2
5 3 34
1 4 1
9 4 2
5 3 3
1 3 3
5 3 2
3 4 5
6 7 5
5 3 8
1 1 1
1 2 1
1 1 1
14
12
TAT
- /*
- hdu 5445 多重背包
- problem:
- 给一场运动会提供食物,每种食物提供ti能量,占用vi空间,最多可提供ui个,把食物运到指定地点,每种车可以运送ai体积的
- 食物,消耗bi的金钱,总共有ci个这种车,问给运动会提供至少p的能量,最少需要花多少运费
- (每个食物可以拆开来运)
- solve:
- 可以将其分成两个多重背包计算,先计算出运送指定能量的食物最少需要多少的空间,然后在这个空间的基础上计算最少需要
- 的花费.结果RE,后来发现这个空间可能很大.
- 而题目中说了50000这个界限,所以直接计算出50000的花费能够达到的最大空间
- hhh-2016-08-17 15:13:15
- */
- #include <algorithm>
- #include <iostream>
- #include <cstdlib>
- #include <cstdio>
- #include <cstring>
- #include <vector>
- #include <map>
- #define lson i<<1
- #define rson i<<1|1
- #define ll long long
- #define key_val ch[ch[root][1]][0]
- using namespace std;
- const int maxn = 1010;
- const int inf = 0x3f3f3f3f;
- int dp[51000];
- int ta,a,c;
- void cal_min(int cost,int val,int num,int m)
- {
- if(cost * num >= m)
- {
- for(int i = cost; i <= m; i++)
- {
- dp[i] = min(dp[i],dp[i-cost] + val);
- }
- }
- else
- {
- int k = 1;
- while(k < num)
- {
- for(int i = m; i >= cost*k; i--)
- dp[i] = min(dp[i],dp[i-cost*k]+val*k);
- num -= k;
- k *= 2;
- }
- for(int i = m; i >= cost*num; i--)
- dp[i] = min(dp[i],dp[i-cost*num]+val*num);
- }
- }
- void cal_max(int cost,int val,int num,int m)
- {
- if(cost * num >= m)
- {
- for(int i = cost; i <= m; i++)
- {
- dp[i] = max(dp[i],dp[i-cost] + val);
- }
- }
- else
- {
- int k = 1;
- while(k < num)
- {
- for(int i = m; i >= cost*k; i--)
- dp[i] = max(dp[i],dp[i-cost*k]+val*k);
- num -= k;
- k *= 2;
- }
- for(int i = m; i >= cost*num; i--)
- dp[i] = max(dp[i],dp[i-cost*num]+val*num);
- }
- }
- int main()
- {
- // freopen("in.txt","r",stdin);
- int n,m,cnt;
- int T;
- cin >> T;
- while(T--)
- {
- memset(dp,inf,sizeof(dp));
- dp[0] = 0;
- scanf("%d%d%d",&n,&cnt,&m);
- for(int i = 1; i <= n; i++)
- {
- scanf("%d%d%d",&a,&c,&ta);
- cal_min(a,c,ta,m + 100); //因为每个能量最多100,所以最大界限为m+100
- }
- int minpart = inf;
- for(int i = m; i <= m+100; i++)
- {
- minpart = min(minpart,dp[i]);
- }
- // cout <<"m:" <<m <<" min:"<<minpart <<endl;
- memset(dp,0,sizeof(dp));
- for(int i = 1; i <= cnt; i++)
- {
- scanf("%d%d%d",&a,&c,&ta);
- cal_max(c,a,ta,50000+100);
- }
- int ans = inf;
- for(int i = 0;i <= 50000;i++){
- if(dp[i] >= minpart)
- {
- ans = i;
- break;
- }
- }
- if(ans == inf)
- printf("TAT\n");
- else
- printf("%d\n",ans);
- }
- return 0;
- }
hdu 5445 多重背包的更多相关文章
- hdu 2191 多重背包 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活
http://acm.hdu.edu.cn/showproblem.php?pid=2191 New~ 欢迎“热爱编程”的高考少年——报考杭州电子科技大学计算机学院关于2015年杭电ACM暑期集训队的 ...
- Big Event in HDU(HDU 1171 多重背包)
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- HDU 1171 Big Event in HDU (多重背包)
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- HDU1171--Big Event in HDU(多重背包)
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- Big Event in HDU(多重背包套用模板)
http://acm.hdu.edu.cn/showproblem.php?pid=1171 Big Event in HDU Time Limit: 10000/5000 MS (Java/Othe ...
- hdu 1059 (多重背包) Dividing
这里;http://acm.hdu.edu.cn/showproblem.php?pid=1059 题意是有价值分别为1,2,3,4,5,6的商品各若干个,给出每种商品的数量,问是否能够分成价值相等的 ...
- 题解报告:hdu 1171 Big Event in HDU(多重背包)
Problem Description Nowadays, we all know that Computer College is the biggest department in HDU. Bu ...
- HDU 1114 完全背包 HDU 2191 多重背包
HDU 1114 Piggy-Bank 完全背包问题. 想想我们01背包是逆序遍历是为了保证什么? 保证每件物品只有两种状态,取或者不取.那么正序遍历呢? 这不就正好满足完全背包的条件了吗 means ...
- hdu 1059 多重背包
题意:价值分别为1,2,3,4,5,6的物品个数分别为a[1],a[2],a[3],a[4],a[5],a[6],问能不能分成两堆价值相等的. 解法:转化成多重背包 #include<stdio ...
随机推荐
- 第二周c语言PTA作业留
6-1 计算两数的和与差(10 分) 本题要求实现一个计算输入的两数的和与差的简单函数. 函数接口定义: void sum_diff( float op1, float op2, float psum ...
- 201421123042 《Java程序设计》第7周学习总结
1. 本周学习总结 1.1 思维导图:Java图形界面总结 2.书面作业 1. GUI中的事件处理 1.1 写出事件处理模型中最重要的几个关键词. 事件源 事件对象 事件监听器 事件适合配器 1.2 ...
- linux系统命令学习系列-用户切换命令su,sudo
先复习一下上节内容: 用户组添加groupadd 用户组修改groupmod 用户组删除groupdel 作业创建一个id为501的组group1,然后改成group2, 同时id变为502,最后删除 ...
- thinkphp调试技巧
调试的经验:很多时候程序调试不出来,但是又找不出错误,往往是拼写错误可能是很小的拼写错误,很难看出,或者多了一个空格,比如在配置路由的时候'URL_ROUTER_ON '=true,这样设置就会错误, ...
- css3兼容IE8的方案 各个ie的hack
虽然现在很多项目已经对低版本IE不要求了,但是还有部分公司对IE8还是很执着的,咱作为屌丝前端程序员不能和老板说前端潮流,不能说趋势,只能动脑子了,下面就分享一些css3兼容ie8的方案思路.主要是实 ...
- 微信小程序组件学习中
一.轮播图 wxml代码: <swiper indicator-dots="true" autoplay="true" duration="10 ...
- MySQL命令(逐步更新ing)
启动mysql 开启: /etc/init.d/mysqld start关闭: /etc/init.d/mysqld stop重启: /etc/init.d/mysqld restart 查看m ...
- 对于错误“Refused to execute script from '...' because its MIME type ('') is not executable, and strict MIME type checking is enabled.”的处理。
今天在是用公司的报表插件Stimulsoft时发现的问题.之前可以正常使用,突然不能加载了.查看发现得到这个错误. 查看请求头 可以看到,请求正常响应,但是发现 Content-Type是空的,但是引 ...
- 如何从0开发一个Atom组件
最近用Atom写博客比较多,然后发现一个很严重的问题..没有一个我想要的上传图片的方式,比如某乎上边就可以直接copy/paste文件,然后进行上传.然而在Atom上没有找到类似的插件,最接近的一个, ...
- python——常用模块2
python--常用模块2 1 logging模块 1.1 函数式简单配置 import logging logging.debug("debug message") loggin ...