Topic Links:
Hdu 5445 Food Problem
Title Description:
There are n kinds of desserts, each with three attributes (energy, space, number), and M trucks, each with three attributes (space, cost, number). What is the minimum cost for a dessert that transports p energy at least?
Problem Solving Ideas:
It can be seen that multiple backpacks are made two times, but the data range is too large, the backpack to 2*1e6, feeling will tle. or stay to write a one, decisive super Ah! And then rolled back to see the backpack nine lectures, saw the binary compression when the feeling can engage in this topic. Try a bit really AC, the original number of items is 100*100, the binary compression is the 100*log2 or so, then 01 backpack on the OK!
1#include <cstdio>2#include <cstring>3#include <iostream>4#include <algorithm>5 using namespacestd;6 Const intINF =0x3f3f3f3f;7 Const intMAXN =55000;8 Const intN = -;9 intDP[MAXN], x, y, C1, C2;Ten intDcos[n], dval[n], tcos[n], tval[n]; One voiddisplay () A { - for(intI=0; i<c1+ $; i++) -Dp[i] =INF; thedp[0] =0; - for(intI=0; i<x; i++) - for(intj=c1+ $; j>=dval[i]; j--) -Dp[j] = min (dp[j], dp[j-dval[i]]+dcos[i]); +C2 =DP[C1]; - for(intI=C1; i<c1+ $; i++) +C2 =min (dp[i], C2); A } at voidSolve () - { -Memset (DP,0,sizeof(DP)); - for(intI=0; i<y; i++) - for(intj=50000; j>=tcos[i]; j--) -DP[J] = max (Dp[j], dp[j-tcos[i]]+tval[i]); in for(intI=1; i<=50000; i++) - if(Dp[i] >=C2) to { +printf ("%d\n", i); - return ; the } *printf ("tat\n"); $ }Panax Notoginseng intMain () - { the intt, N, M; +scanf ("%d", &t); A while(T--) the { +scanf (" %d%d%d", &n, &m, &C1); - intA, B, C; $x = y =0; $ for(intI=0; i<n; i++) - { -scanf (" %d%d%d", &a, &b, &c); the for(intk=1; C k*=2) - {Wuyi intnum =min (k, c); theDCOS[X] = num *b; -dval[x++] = num *A; WuC-=num; - } About } $ for(intI=0; i<m; i++) - { -scanf (" %d%d%d", &a, &b, &c); - for(intk=1; C k*=2) A { + intnum =min (k, c); theTCOS[Y] = num *b; -tval[y++] = num *A; $C-=num; the } the } the display (); the solve (); - } in return 0; the}
Hdu 5445 Food problem (2015 Changchun Online tournament ACM/ICPC Asia Regional Changchun Online)