Food problem
Time Limit:1 Sec
Memory limit:256 MB
Topic Connection 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 is 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 has Different costs. However, you could split a single dessert to several parts and put them on different trucks, then assemble the parts at th E Game Arena. Note that the a dessert does not provide the if some part of the it is missing.
Bell wants to know what much would it cost in least to provide desserts of a total energy of P (most of the desserts is no T bought with money, so we assume obtaining the desserts costs no money, only the cost of transportation should is conside Red). Unfortunately the mathematician is has trouble with his stomach, so this problem are 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 is three integers n,m,p on the first line (1≤n≤200,1≤m≤200,0≤p≤50000), representing the number O F 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 de Ssert can provide TI Energy, takes up space of the size UI and that Bell can prepare at the most VI of them.
On each of the next m lines, there is also three integers xj,yj,zj (1≤xj≤100,1≤yj≤100,1≤zj≤100) indicating that the j−th t Ruck can carry at the most size of XJ, hiring each one costs YJ and so Bell can hire at the 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's possible an D It 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
Test instructions
Give you some sugar, there is volume and value and quantity, candy can be divided
And then give you some backpacks, each backpack needs money, can be loaded with a volume of V candy, and then a K backpack
Ask you how much the minimum cost to buy a backpack, can get p point value of candy
Exercises
Split the candy and put the backpack together, as a volume to do
DP1[P] indicates that volume is the smallest candy volume of P
Dp2[s] represents the maximum volume that money can get when it is s
Requires binary optimization/monotonic queue optimization
Code:
#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 unsignedChar byte;#definePB Push_back#defineInput_fast Std::ios::sync_with_stdio (false); Std::cin.tie (0)#defineLocal Freopen ("In.txt", "R", stdin)#definePi ACOs (-1)using namespacestd;Const intMAXN = $+ the;structitem{intVal, size; };structitem2{intsize, cost; };intN, M, p, sz[maxn],dp1[50000+ -],sz2[maxn],dp2[50000+ -];item2 b[maxn][ -]; Item a[maxn][ -];voidInitiation () {memset (SZ,0,sizeof(SZ)); memset (SZ2,0,sizeof(SZ2)); scanf ("%d%d%d",&n,&m,&p); for(inti =1; I <= N; ++i) {intV, sq, number, cot =0; scanf ("%d%d%d",&v,&sq,&Number ); for(intj =1; ; J <<=1) { if(cot + J >Number ) { intDCV = number-Cot; if(DCV! =0) {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(inti =1; I <= m; ++i) {intV, sq, number, cot =0; scanf ("%d%d%d",&v,&sq,&Number ); for(intj =1; ; J <<=1) { if(cot + J >Number ) { intDCV = number-Cot; if(DCV! =0) {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; }}}inlinevoidUpdata (int& X,intv) {x=min (x, v);} InlinevoidUPDATA2 (int& X,intv) {x=Max (x, v);}voidsolve () {memset (DP1,0x3f,sizeof(DP1)); dp1[0] =0; intError = dp1[1]; for(inti =1; I <= N; ++i) { for(intz =0; Z < sz[i]; ++z) { for(intj = P-1; J >=0; --j) {if(Dp1[j] = = error)Continue; intNEWJ = j +A[i][z].val; intNewcost = Dp1[j] +a[i][z].size; if(NEWJ >= p) newj=p; Updata (Dp1[newj],newcost); } } } if(Dp1[p] = =error) {printf ("tat\n"); return; } intNeed =Dp1[p]; memset (DP2,0,sizeof(DP2)); for(inti =1; I <= m; ++i) { for(intz =0; Z < sz2[i]; ++z) {intCost =B[i][z].cost; intSize =b[i][z].size; for(intj = 5e4; J >= Cost; --J) Updata2 (Dp2[j], Dp2[j-cost] +size); } } intAns =-1; for(inti =0; I <= 5e4; ++i) {if(Dp2[i] >=need) {ans=i; Break; } } if(~ans) printf ("%d\n", ans); Elseprintf"tat\n");}intMainintargcChar*argv[]) { intCase ; scanf ("%d",&Case ); while(case--) {initiation (); Solve (); } return 0;}
Hdu 5445 Food problem multiple backpack