Algorithm: POJ 2392 space Elevator (DP sort + multiple Backpack)

Source: Internet
Author: User

The main effect of the topic:

There are n kinds of bricks, the height of each brick is H, the quantity is C, and the highest position of it can not exceed a. How high can these bricks be stacked?

Ideas:

First of all kinds of bricks according to a from large to small sort, and then directly set multiple backpacks can be.

Code:

 #include <iostream> #include <queue> #include <stack> #include <cstdio> #include <cstr ing> #include <cmath> #include <map> #include <set> #include <string> #define MP Make_pai R #define SQ (x) (x) #define MAX (x, y) ((x) > (y))?  
(x):(y) typedef int int64;  
Const double PI = ACOs (-1.0);  
const int INF = 0X3F3F3F3F;  
      
using namespace Std;  
      
const int MAXN = 33;  
      
int n, m;      
    struct node{int h, a, C;  
    BOOL operator< (const node& RHS) Const {return a < RHS.A;  
      
}}arr[410]; inline void Zeroonepack (int* f, int V, int c, int w) {for (int i=v; i>=c;-i) f[i] = max (f[i), f[i-c]+  
W); } inline void Completepack (int* f, int V, int c, int w) {for (int i=c; i<=v; ++i) f[i] = max (f[i), f[  
I-C]+W); } inline void Multiplepack (int* f, int V, int c, int w, int m) {if (c*m >= V) {Completepack (f, V, C, W);  
    return;  
    int k = 1;  
        while (K < m) {Zeroonepack (F, V, K*c, k*w);  
        M-= k;  
    K <<= 1;  
} zeroonepack (f, V, M*c, m*w);  
      
int f[100010];  
    int main () {scanf ("%d", &n);  
    int maxx = 0;  
        for (int i=1; i<=n; ++i) {scanf ("%d%d%d", &arr[i].h,&arr[i].a,&arr[i].c);  
    Maxx = Max (Maxx, ARR[I].A);  
      
    Sort (arr+1, arr+1+n);  
      
    for (int i=0; i<=maxx; ++i) f[i] = 0;  
      
    for (int i=1; i<=n; ++i) Multiplepack (f, arr[i].a, Arr[i].h, Arr[i].h, arr[i].c);  
    int ans = 0;  
    for (int i=0; i<=maxx; ++i) ans = max (ans, f[i]);  
    printf ("%d\n", ans);  
return 0; }

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

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.