题目描述:

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(T≤10) representing the number of test cases.

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 ti energy, 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.

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

题目分析:
有一些cookie,每一种cookie都有其特定的energy,但也要占特定的volume,每一种cookie都有数量num。同时你拥有一些运载cookie的truck,每种truck也可以装载特定volume的cookie,每种truck需要特定的prize,每种truck也有特定数量num。
求将所有cookie都装载在truck中,求花费最小的prize,如果不能讲所有cookie装满,输出“TAT”。
因为在cookie装在truck是只计算volume值的,就是说可以将一种cookie分别装在不同的truck上。
要进行两次的多重背包,第一次对cookie的energy进行一次多重背包,找出最小的volume值。第二次对truck的prize进行一次多重背包,找出最小的volume值。这两次多重背包的结果根据volume值建立联系。最后再根据找一遍prize得出最终的答案。
(ps:这题需要进行二进制优化 不然要TLE)

代码如下:

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>const int INF = 0x3f3f3f3f;
const int MAXN =65000;
using namespace std;int dp[MAXN];//在第一次中,dp[i]表示在获得energy为i时最小的vol体积//在第二次中,dp[i]表示在花费prize为i时最小的vol体积
struct Cookie
{int val,vol,t;
}cookie[220];struct Truck
{int vol,prize,t;
}truck[220];int Mul_Pack1(Cookie cookie[], int n)//第一次多重背包
{memset(dp,INF,sizeof(dp));dp[0]=0;for(int i=1; i<=n; i++)//遍历每一种cookie{int t=cookie[i].t;for(int j=1; t>0; j<<=1)//寻找该种cookie选择次数{int tmp=min(t,j);//需要优化for(int k=60000; k>=cookie[i].val*tmp; k--)//对其energy进行dp{dp[k]=min(dp[k-cookie[i].val*tmp]+cookie[i].vol*tmp,dp[k]);}t-=tmp;}}
}int Mul_Pack2(Truck truck[],int n)
{memset(dp,0,sizeof(dp));for(int i=1; i<=n; i++){int t=truck[i].t;for(int j=1; t>0; j<<=1){//需要优化int tmp=min(t,j);for(int k=60000; k>=truck[i].prize*tmp; k--){dp[k]=max(dp[k-truck[i].prize*tmp]+truck[i].vol*tmp,dp[k]);}t-=tmp;}}
}int T;
int main()
{int n,m,p;scanf("%d",&T);while(T--){scanf("%d%d%d",&n,&m,&p);for(int i=1; i<=n; i++)scanf("%d%d%d",&cookie[i].val,&cookie[i].vol,&cookie[i].t);for(int i=1; i<=m; i++)scanf("%d%d%d",&truck[i].vol,&truck[i].prize,&truck[i].t);Mul_Pack1(cookie,n);int minv=INF;//记录最小体积for(int i=p; i<=60000; i++){minv=min(dp[i],minv);}if (minv==INF){printf("TAT\n");continue;}Mul_Pack2(truck,m);bool f=false;int num;for(int i=1; i<=60000; i++){if (dp[i]>=minv && dp[i]!=INF){f=true;num=i;break;}}if (f) printf("%d\n",num);else printf("TAT\n");}return 0;
}

HDU 5445 Food Problem 两次多重背包相关推荐

  1. hdu 5445 Food Problem (多重背包)

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5445 题解:一看就像多重背包就是怎么看都不好做.但是这里有点明显的就是有两个背包,一个是糖 ...

  2. HDU 5445 Food Problem 多重背包+二进制优化

    据说也可以用单调队列优化多重背包,但是我不会,所以还是选择了二进制优化... 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5445 题意:先给n,m, ...

  3. [HDU 5445]Food Problem[多重背包]

    题目链接:[HDU 5445]Food Problem[多重背包] 题意分析: 有n种类型的点心,每种提供t的能量,占据u的空间,有v个: 有m种类型的卡车,每种容量x,雇佣花费y,能提供z辆: 点心 ...

  4. HDU 5445 Food Problem(多重背包)

    Description n种点心,每种点心有一定的能量t,体积u和数量v,现在要用m种卡车搬运这些点心,每种开车有一定的容量x,花费y和数量z,点心可以分割但选一块就要都选,现在问将运送总能量不小于p ...

  5. hdu5445(两次多重背包)

    链接:点击打开链接 题意:有n种甜点,每种都有三个属性(能量,空间,数目),有m辆卡车,每种都有是三个属性(空间,花费,数目),问至少运输p能量的甜点,花费最小是多少 代码: #include < ...

  6. Hdu 5445 Food Problem 多重背包

    题意:给出n,m,p,分别表示有n种点心,m种卡车,能量p. 然后给出每种点心所能获得的能量,所占卡车的体积,以及每种点心的数量. 再给出每种卡车所能装下的空间,租这种卡车的费用,以及每种卡车的数量. ...

  7. HDU 5445:Food Problem

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5445 题目翻译: 有N种甜点,M种卡车,至少需要P点能量. 然后给出N个 t, u, v,t是甜点能提 ...

  8. HDU 5445 Food Problem

    题意:有n种糖果,m种箱子,需要的能量为p.每种糖果有它的能量.体积.数量,每种箱子有它的容量.价格.数量,问至少获得p能量的前提下,最少花多少钱 思路:首先可以知道这是一个背包,然后可以求出能量为i ...

  9. HDU 5445 (多重背包)

    题目链接:点击这里 题意: 有n个物品, m个卡车. 已知每种物品的能量, 体积和数量还有每种卡车的体积, 花费和数量, 求至少得到p能量的最少的卡车花费. 物品装卡车的时候能够切开装. 两次多重背包 ...

最新文章

  1. 一文读懂Spring中的AOP机制
  2. Tomcat是什么:Tomcat与Java技、Tomcat与Web应用以及Tomcat基本框架及相关配置
  3. Hadoop学习之MapReduce(二)
  4. labview随机数序列_labview产生随机数
  5. 51单片机计算器_基于51单片机的倒计时温度检测报警器
  6. 自己在总结前人经验下弄的几个opencv封装函数
  7. python基础教程期末考试题库_PYTHON语言应用试题题目及答案,课程2020最新期末考试题库,章节测验答案...
  8. yuv图片拼接 java_java利用ffmpeg把图片转成yuv格式
  9. 云盘上传一直显示服务器出错_百度云盘一直服务器忙 百度网盘出现服务器错误...
  10. Vibe算法简介、优缺点、代码
  11. 嵌入式开发 | 单片机产品开发流程及学习方法
  12. 用vmware安装gho文件
  13. Android 9.0系统软件进入视频界面发生闪退
  14. 微信朋友圈附近推效果怎么样?
  15. linux桌面添加第三方软件图标
  16. 网络摄像头无插件直播H265编码视频播放器EasyPlayer网页播放器不能播放怎么处理?
  17. 通过公众号迁移快速开通留言功能方法
  18. Lined List
  19. 传输加载优化(资源压缩、资源缓存、HTTP2)
  20. dll文件加载运行加载的14001错误,由于应用程序配置不正确,应用程序未能启动

热门文章

  1. 微信小程序使用图片标签出现白底
  2. 摄氏度符号英文计算机语言,英文文章里摄氏度符号打法
  3. 链表中入口结点——《剑指offer》
  4. 最新2023年3月编程排行榜出炉,Python太牛了
  5. Cadence PCB层的概念
  6. 阿里副总裁凌晨4 点“逃离上海”?贾扬清回应是前往美国看病,网友:双面人!...
  7. 432. 全 O(1) 的数据结构
  8. JavaScript DOM编程艺术——综合案例
  9. SASE部署及应用场景探讨
  10. PPTP 服务器配置