U-space Elevator Time
limit:1000MS
Memory Limit:65536KB
64bit IO Format:%i64d &%i64 U Submit Status
Description
The cows is going to space! They plan to achieve orbit by building a sort of space elevator:a giant Tower of blocks. They has K (1 <= k <=) different types of blocks with which to build the tower. Each block of type I has a height h_i (1 <= h_i <=) and is available in quantity c_i (1 <= c_i <= 10). Due to possible damage caused by cosmic rays, no part of a block of type I can exceed a maximum altitude a_i (1 <= a_i <= 40000).
Help the cows build the tallest space elevator possible by stacking blocks on top of each of the other according to the rules.
Input
* Line 1: A single integer, K
* Lines 2..k+1:each line contains three space-separated integers:h_i, a_i, and c_i. Line i+1 describes block type I.
Output
* Line 1: A single integer H, the maximum height of a tower that can be built
Sample Input
37 40 35 23 82 52 6
Sample Output
48
Hint
OUTPUT DETAILS:
From the Bottom:3 blocks of type 2, below 3 of type 1, below 6 of type 3. Stacking 4 blocks of type 2 and 3 of type 1 are not legal, since the top of the last type 1 block would exceed height 40.
1#include <cstdio>2#include <cstring>3#include <algorithm>4 using namespacestd;5 Const intMAX =40010;6 Const intINF =0x3f3f3f3f;7 8 structNode9 {Ten inth; One intA; A intC; - }; - the intans; - BOOLVis[max]; - Node Block[max]; - + BOOLCMP (Node A, Node B) - { + return(A.A <B.A); A } at - voidZero_pack (intWintv) - { - for(inti = V; I >= W; i--) - if(vis[i-W]) - { inVis[i] =true; -Ans =Max (ans,i); to } + } - the voidComplete_pack (intWintv) * { $ for(inti = W; I <= v; i++)Panax Notoginseng if(Vis[i-W]) - { theVis[i] =true; +Ans =Max (ans,i); A } the } + - voidMulti_pack (intWintNintv) $ { $ if(w * n >v) - Complete_pack (w,v); - Else the { - for(inti =1; I < n; I *=2)Wuyi { theN-=i; -Zero_pack (W *I, v); Wu } - AboutZero_pack (n *w,v); $ } - } - - intMain () A { + #ifdef OFFLINE theFreopen ("In.txt","R", stdin); -Freopen ("OUT.txt","W", stdout); $ #endif the theAns =0; thememset (Vis,false,sizeof(Vis)); the - intK; inscanf"%d", &k); the for(inti =0; I < K; i++) thescanf"%d%d%d", &block[i].h, &BLOCK[I].A, &block[i].c); About thevis[0] =true; theSort (block, block +K, CMP); the + for(inti =0; I < K; i++) - Multi_pack (block[i].h, BLOCK[I].C, block[i].a); the Bayiprintf"%d\n", ans); the return 0; the -}View Code
Dynamic Planning _ Multiple backpacks: Space Elevator