POJ 2392 Space Elevator (Multi-pack + First Order)

Source: Internet
Author: User

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 <= 400 ) different Types of blocks with which to build the tower. Each block of type I have height h_i (1  <= h_i <= 100 ) 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

12..  K +1: Contains three space-separated integers:h_i, a_i, and c_i. Line i+1 describes block type I.

Output

1: A single integer H, the maximum height of a tower, which can be built

Sample Input

3 7  + 3 5  at 8 2  the 6

Sample Output

48

Hint

3 2 3 1 6 3 4 2 3 1  is 1 .

Source

Usaco 2005 March Gold This problem and POJ 1742 is a bit similar, but this problem to first by the maximum height of each block ranking, so that the purpose is to obtain the best solution, how to prove? The DP Array is then initialized to -1,dp=-1, which means that dp[i]>=0 indicates how many more can be left when I is taken. The final result is to search for the value of dp[i]!=-1 from the maximum height, and the direct output can be
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5#include <map>6#include <Set>7 using namespacestd;8 #defineN 4069 #defineM 40006Ten structnode{ One     inth,a,c; A }block[n]; - intdp[m*N]; - BOOLCMP (Node A,node b) { the     returna.a<B.A; - } - intMain () - { +     intN; -      while(SCANF ("%d", &n) = =1){ +          for(intI=0; i<n;i++){ Ascanf"%d%d%d",&block[i].h,&block[i].a,&block[i].c); at         } -Sort (block,block+n,cmp); -  -memset (dp,-1,sizeof(DP)); -dp[0]=0; -         for(intI=0; i<n;i++){ in             for(intj=0; j<=m;j++){ -                if(dp[j]>=0){ todp[j]=block[i].c; +                } -                Else if(J<block[i].h | | dp[j-block[i].h]<=0){ thedp[j]=-1; *                } $                Else if(j>block[i].a) {Panax Notoginsengdp[j]=-1; -                } the                Else{ +dp[j]=dp[j-block[i].h]-1; A                } the            } +        } -         for(inti=m;i>=0; i--){ $           if(dp[i]!=-1){ $printf"%d\n", i); -               Break; -           } the        } - Wuyi  the  -  Wu  -     } About     return 0; $}
View Code

POJ 2392 Space Elevator (Multi-pack + First Order)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.