博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 5445 多重背包
阅读量:7122 次
发布时间:2019-06-28

本文共 4407 字,大约阅读时间需要 14 分钟。

Food Problem

Time Limit: 3000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)

Total Submission(s): 1243    Accepted Submission(s): 368

Problem Description
Few days before a game of orienteering, Bell came to a mathematician to solve a big problem. Bell is preparing the dessert for the game. There are several different types of desserts such as small cookies, little grasshoppers and tiny mantises. Every type of dessert may provide different amounts of energy, and they all take up different size of space.
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.
 

 

Input
The first line of input contains a integer 
T(T10) representing the number of test cases.
For each test case there are three integers n,m,p on the first line (1n200,1m200,0p50000), representing the number of different desserts, the number of different trucks and the least energy required respectively.
The ith of the n following lines contains three integers ti,ui,vi(1ti100,1ui100,1vi100) indicating that the ith 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(1xj100,1yj100,1zj100) indicating that the jth truck can carry at most size of xj , hiring each one costs yj and that Bell can hire at most zj of them.
 

 

Output
For every test case output the minimum cost to provide the dessert of enough energy in the game arena if it is possible and its cost is no more than 
50000. Otherwise, output TAT on the line instead.
 

 

Sample Input
4 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
 

 

Sample Output
4 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 
#include
#include
#include
#include
#include
#include
#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:" <
<<" min:"<
<
<= 50000;i++){ if(dp[i] >= minpart) { ans = i; break; } } if(ans == inf) printf("TAT\n"); else printf("%d\n",ans); } return 0;}

  

转载于:https://www.cnblogs.com/Przz/p/5792161.html

你可能感兴趣的文章
设置接口跨域调用方法
查看>>
python selenium系列(八)元素定位进阶之分层定位
查看>>
MySQL多表连接优化一例
查看>>
PHP动态扩展模块安装
查看>>
AgileEAS.NET平台开发实例-药店系统-UI层重构技巧及其他
查看>>
我的友情链接
查看>>
Shell开发的一些技巧和经验
查看>>
5-2 array 数组的赋值及遍历
查看>>
Go编程基础 - 类型与变量
查看>>
外链优化的发展
查看>>
集合类操作优化经验总结(三)
查看>>
内存数据库 eXtreme db 插入测试
查看>>
我的友情链接
查看>>
html input readonly 和 disable的区别
查看>>
Firebug控制台详解,让调试js代码变得更简单
查看>>
无法访问Docker容器映射到宿主上的端口
查看>>
Gmagick最新版本安装错误
查看>>
Outlook配置
查看>>
RocketMQ-安装
查看>>
RadixSort(基数排序)
查看>>