Food Problem

Time Limit: 1 Sec

Memory Limit: 256 MB

题目连接

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

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

HINT

题意

给你一些糖,有体积和价值和数量,糖果是可以拆分的

然后给你一些背包,每个背包需要钱,可以装v的体积糖果,然后有k个背包

问你最小多少花费买背包,可以获得p点价值的糖果

题解:

拆分糖果就把背包合在一起就好了,当成体积来做

dp1[p]表示体积是P的最小糖果体积

dp2[s]表示money是s时能够获得的最大体积

需要二进制优化/单调队列优化

代码:

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <string>
#include <ctime>
#include <list>
#include <bitset>
typedef unsigned char byte;
#define pb push_back
#define input_fast std::ios::sync_with_stdio(false);std::cin.tie(0)
#define local freopen("in.txt","r",stdin)
#define pi acos(-1) using namespace std;
const int maxn = + ; struct item
{
int val , size;
}; struct item2
{
int size , cost;
}; int n , m , p ,sz[maxn],dp1[+],sz2[maxn],dp2[+];
item2 B[maxn][] ;
item A[maxn][]; void initiation()
{
memset( sz , ,sizeof(sz));
memset( sz2,,sizeof(sz2));
scanf("%d%d%d",&n,&m,&p);
for(int i = ; i <= n ; ++ i)
{
int v , sq , number , cot = ;
scanf("%d%d%d",&v,&sq,&number);
for(int j = ; ; j <<= )
{
if(cot + j > number)
{
int dcv = number - cot;
if(dcv != )
{
A[i][sz[i]].val = dcv*v;
A[i][sz[i]].size = dcv*sq;
sz[i]++;
}
break;
}
A[i][sz[i]].val = v*j;
A[i][sz[i]].size = sq*j;
sz[i]++;
cot += j;
}
}
for(int i = ; i <= m ; ++ i)
{
int v , sq , number , cot = ;
scanf("%d%d%d",&v,&sq,&number);
for(int j = ; ; j <<= )
{
if(cot + j > number)
{
int dcv = number - cot;
if(dcv != )
{
B[i][sz2[i]].size = dcv*v;
B[i][sz2[i]].cost = dcv*sq;
sz2[i]++;
}
break;
}
B[i][sz2[i]].size = v*j;
B[i][sz2[i]].cost = sq*j;
sz2[i]++;
cot += j;
}
}
} inline void updata(int & x,int v)
{
x = min(x , v);
} inline void updata2(int & x,int v)
{
x = max(x , v);
} void solve()
{
memset(dp1,0x3f,sizeof(dp1));dp1[] = ;
int error = dp1[];
for(int i = ; i <= n ; ++ i)
{
for(int z = ; z < sz[i] ; ++ z)
{
for(int j = p - ; j >= ; -- j)
{
if(dp1[j] == error ) continue;
int newj = j + A[i][z].val;
int newcost = dp1[j] + A[i][z].size;
if(newj >= p ) newj=p;
updata(dp1[newj],newcost);
}
}
}
if(dp1[p] == error)
{
printf("TAT\n");
return;
}
int need = dp1[p];
memset(dp2,,sizeof(dp2));
for(int i = ; i <= m ; ++ i)
{
for(int z = ; z < sz2[i] ; ++ z)
{
int cost = B[i][z].cost;
int size = B[i][z].size;
for(int j = 5e4 ; j >= cost ; -- j) updata2(dp2[j] , dp2[j-cost] + size);
}
}
int ans = -;
for(int i = ; i <= 5e4 ; ++ i)
{
if(dp2[i] >= need)
{
ans = i;
break;
}
}
if(~ans) printf("%d\n",ans);
else printf("TAT\n");
} int main(int argc,char *argv[])
{
int Case;
scanf("%d",&Case);
while(Case--)
{
initiation();
solve();
}
return ;
}

hdu 5445 Food Problem 多重背包的更多相关文章

  1. Hdu 5445 Food Problem (2015长春网络赛 ACM/ICPC Asia Regional Changchun Online)

    题目链接: Hdu  5445 Food Problem 题目描述: 有n种甜点,每种都有三个属性(能量,空间,数目),有m辆卡车,每种都有是三个属性(空间,花费,数目).问至少运输p能量的甜点,花费 ...

  2. HDOJ(HDU).2844 Coins (DP 多重背包+二进制优化)

    HDOJ(HDU).2844 Coins (DP 多重背包+二进制优化) 题意分析 先把每种硬币按照二进制拆分好,然后做01背包即可.需要注意的是本题只需要求解可以凑出几种金钱的价格,而不需要输出种数 ...

  3. HDOJ(HDU).1059 Dividing(DP 多重背包+二进制优化)

    HDOJ(HDU).1059 Dividing(DP 多重背包+二进制优化) 题意分析 给出一系列的石头的数量,然后问石头能否被平分成为价值相等的2份.首先可以确定的是如果石头的价值总和为奇数的话,那 ...

  4. HDU 5445 Food Problem(多重背包+二进制优化)

    http://acm.hdu.edu.cn/showproblem.php?pid=5445 题意:现在你要为运动会提供食物,总共需要提供P能量的食物,现在有n种食物,每种食物能提供 t 能量,体积为 ...

  5. HDU 5445——Food Problem——————【多重背包】

    Food Problem Time Limit: 3000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)To ...

  6. hdu 2844 Coins (多重背包)

    题意是给你几个数,再给你这几个数的可以用的个数,然后随机找几个数来累加, 让我算可以累加得到的数的种数! 解题思路:先将背包初始化为-1,再用多重背包计算,最后检索,若bb[i]==i,则说明i这个数 ...

  7. 题解报告:hdu 1059 Dividing(多重背包、多重部分和问题)

    Problem Description Marsha and Bill own a collection of marbles. They want to split the collection a ...

  8. hdu 1059 Dividing bitset 多重背包

    bitset做法 #include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a ...

  9. HDU 2844 Coins(多重背包)

    点我看题目 题意 :Whuacmers有n种硬币,分别是面值为A1,A2,.....,An,每一种面值的硬币的数量分别是C1,C2,......,Cn,Whuacmers想买钱包,但是想给人家刚好的钱 ...

随机推荐

  1. Android-xUtils框架介绍(二)

    昨天对xUtils整体上做了一个简单的介绍,今天咱们就代码码起,真刀实枪的也看看,看看如何快速便捷的把xUtils给集成到大家的项目中去.xUtils中有四大组件可以供我们使用,分别是ViewUtil ...

  2. ADT开发中的一些优化设置:代码背景色、代码字体大小、代码自动补全

    初学Android开发,在网上找到一些ADT工具的优化,自己设置好了,截图保存下来.免得以后忘了. 1. 设置背景颜色: 色调85.饱和度90.亮度205 RGB:199.237.204 2. 设置代 ...

  3. poj 1080 Human Gene Functions(dp)

    题目:http://poj.org/problem?id=1080 题意:比较两个基因序列,测定它们的相似度,将两个基因排成直线,如果需要的话插入空格,使基因的长度相等,然后根据那个表格计算出相似度. ...

  4. poj 2676 Sudoku ( dfs )

    dfs 用的还是不行啊,做题还是得看别人的博客!!! 题目:http://poj.org/problem?id=2676 题意:把一个9行9列的网格,再细分为9个3*3的子网格,要求每行.每列.每个子 ...

  5. poj1989

    一道非常神奇的题目 var v:array[0..10010] of boolean; n,k,i,x,ans,s:longint; begin readln(n,k); fillchar(v,siz ...

  6. HDU 4635 Strongly connected(强连通分量,变形)

    题意:给出一个有向图(不一定连通),问最多可添加多少条边而该图仍然没有强连通. 思路: 强连通分量必须先求出,每个强连通分量包含有几个点也需要知道,每个点只会属于1个强连通分量. 在使图不强连通的前提 ...

  7. ubuntuy用户切换和密码修改

    修改当前用户的密码 $passwd 修改用户密码 $sudo passwd 用户名 切换到其他帐号(需要该用户的密码) $su 用户名 切换到root帐号 $sudo -s

  8. VS2010 Chromium编译

    推荐使用Windows 7及以后系统,最少8G内存,预留出50G磁盘空间 搭建Visual Studio 2010开发环境 1.安装Visual Studio 2010专业版或者旗舰版 2.安装VS2 ...

  9. [King.yue]Ext中Grid得到选择行数据的方法总结

    (1)grid.getStore().getRange(0,store.getCount());    //得到grid所有的行 (2)grid.getSelectionModel().getSele ...

  10. 单元测试工具之Xunit

    在.NET开发中的单元测试工具之——xUnit.Net  原始出处 http://zhoufoxcn.blog.51cto.com/792419/1172320 在上一篇<在.NET开发中的单元 ...