hdu5445 || 2015长春网络赛1009题 多重背包问题
来源:互联网 发布:知乎 梁湖清 编辑:程序博客网 时间:2024/05/13 08:20
http://acm.hdu.edu.cn/showproblem.php?pid=5445
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 ofp (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.
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
Input
The first line of input contains a integer T(T≤10) representing the number of test cases.
For each test case there are three integersn,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.
Thei−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 ti energy, takes up space of size ui and that Bell can prepare at most vi of them.
On each of the nextm 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.
For each test case there are three integers
The
On each of the next
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
41 1 714 2 11 2 21 1 1010 10 15 7 25 3 341 4 19 4 25 3 31 3 35 3 23 4 56 7 55 3 81 1 11 2 11 1 1
Sample Output
41412TAT
/**hdu5445 || 2015长春网络赛1009题 多重背包问题题目大意:给一场运动会提供食物,每种食物提供ti能量,占用vi空间,最多可提供ui个,把食物运到指定地点,每种车可以运送ai体积的 食物,消耗bi的金钱,总共有ci个这种车,问给运动会提供至少p的能量,最少需要花多少运费 特别说明:每个食物可以拆开来运解题思路:利用多重背包的二进制方案,先找出提供不少于p的能量需要多少空间V(背包必须全部装满),然后求运送能力大于V的最小背包*/#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>using namespace std;const int maxn=100500;int n,m,p;int c[maxn],w[maxn],dp[maxn];int main(){ int T; scanf("%d",&T); while(T--) { scanf("%d%d%d",&n,&m,&p); int nn=0,t,u,v; for(int i=0; i<n; i++) { scanf("%d%d%d",&t,&u,&v); int k=0; while(v-(1<<(k+1))+1>0)k++; for(int j=0; j<k; j++) { ++nn; c[nn]=t*(1<<j); w[nn]=u*(1<<j); } ++nn; c[nn]=t*(v-(1<<k)+1); w[nn]=u*(v-(1<<k)+1); } memset(dp,0x3f3f3f3f,sizeof(dp)); dp[0]=0; for(int i=1; i<=nn; i++) { for(int j=p+100; j>=c[i]; j--)//单个食物提供能量最大100,因此我们找p~p+100之间的完全装满的最小体积 { dp[j]=min(dp[j],dp[j-c[i]]+w[i]); } } int V=0x3f3f3f3f; for(int i=p; i<=p+100; i++)V=min(dp[i],V); nn=0; for(int i=0; i<m; i++) { scanf("%d%d%d",&u,&t,&v); int k=0; while(v-(1<<(k+1))+1>0)k++; for(int j=0; j<k; j++) { ++nn; c[nn]=t*(1<<j); w[nn]=u*(1<<j); } ++nn; c[nn]=t*(v-(1<<k)+1); w[nn]=u*(v-(1<<k)+1); } memset(dp,0,sizeof(dp)); for(int i=1; i<=nn; i++) { for(int j=50000; j>=c[i]; j--)///最大体积不超过50000 { dp[j]=max(dp[j],dp[j-c[i]]+w[i]); } } int ans = 0x3f3f3f3f; for(int i=50000; i>=0; i--) { if (dp[i] >= V)///找运送体积过V的最小背包即为答案 { ans = min(ans, i); } } if (ans == 0x3f3f3f3f) puts("TAT"); else printf("%d\n", ans); } return 0;}
0 0
- hdu5445 || 2015长春网络赛1009题 多重背包问题
- hdu5445(两次多重背包)
- 2015长春网络赛
- hdu5437(2015长春网络赛A题)
- hdu5438(2015长春网络赛B题)
- hdu5443(2015长春网络赛G题)
- hdu5444(2015长春网络赛H题)
- hdu5441(2015长春网络赛E题)
- hdu5446(2015长春网络赛J题)
- hdu5442(2015长春网络赛F题)
- 2015长春网络赛小结
- 多重背包模板题 背包问题V2
- hdu5445 Food Problem(背包)
- HDU 5445 Food Problem (2015年长春站网络赛1009 多重背包DP)
- 2015年ACM长春赛区网络赛G题
- 2015ACM长春赛区网络赛C题
- 2015ACM长春赛区网络赛H题
- 2015ACM长春赛区网络赛 E题
- (总结)Nginx配置文件nginx.conf中文详解
- PRML 阅读笔记之神经网络(一)
- 使用Chrome Audits功能清理无用的css
- Android Studio利用Gradle删除没有使用到的资源文件
- wget用法
- hdu5445 || 2015长春网络赛1009题 多重背包问题
- 第一次接触cygwin
- Binary Tree Postorder Traversal 非递归实现二叉树后序遍历
- C++抽象类
- Linux下的主要的C语言编译器
- JPG格式照片转PDF格式电子书
- 字符串拷贝
- Android实战简易教程<十七>(LayoutAnimation布局动画)
- Handler Looper MessageQueue 之间的关系