POJ Topic 2392 Space Elevator (multiple backpack)

Source: Internet
Author: User

Space Elevator
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 9042 Accepted: 4296

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.

Source

Usaco 2005 March Gold

AC Code

#include <stdio.h> #include <string.h> #include <stdlib.h> #define INF 1<<30#define Max (A, B) >B?A:B) #define MIN (A, b) (a>b?a:b) struct s{int h,num,mh;} B[440];int dp[40040];int cmp (const void *a,const void *b) {return (* (struct S *) a). mh-(* (struct S *) b). MH; int N;int Main () {while (scanf ("%d", &n)!=eof) {int i,j,k;for (i=0;i<n;i++) {scanf ("%d%d%d", &b[i].h,&b[i ].mh,&b[i].num);} Qsort (B,n,sizeof (b[0]), CMP), memset (Dp,0,sizeof (DP)), for (i=0;i<n;i++) {for (k=1;k<=b[i].num;k++) {for (J=b[i] . mh;j>=b[i].h;j--) {Dp[j]=max (dp[j],dp[j-b[i].h]+b[i].h);}}} int Ans=0;for (i=0;i<=b[n-1].mh;i++) {Ans=max (ans,dp[i]);} printf ("%d\n", ans);}}


POJ Topic 2392 Space Elevator (multiple backpack)

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.