tyvj1086 Elevator

背景

广东汕头聿怀初中 Train#2 Problem4

描述

现有N种箱子,每种箱子高度H_i,数量C_i。现选取若干箱子堆成一列,且第i种箱子不能放在高度超过A_i的地方。试求最大叠放高度。

输入格式

第一行,一个整数,表示箱子种类N。
接下来N行,每行三个整数,表示H_i,A_i,C_i。

输出格式

一个整数,表示最大高度。

测试样例1

输入


7 40 3 
5 23 8 
2 52 6

输出

48

备注

N <= 400 , H_i <= 100 , C_i <= 10 , A_i <= 40000
Vivian Snow

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
int n,k,hc,h[1005],c[1005],a[1005],ans;
bool f[40205];
struct ITM{
    int h;
    int c;
    int a;
}temp;
bool cmp(ITM x,ITM y){
    return x.a < y.a;
}
vector<ITM> itm;
int main(){
    cin>>n;
    for(int i = 1;i <= n;i++){
        scanf("%d%d%d",&h[i],&a[i],&c[i]);
        k = 1;
        while(c[i] >= k){
            temp.a = a[i];
            temp.c = k;
            temp.h = h[i];
            c[i] -= k;
            k <<= 1;
            itm.push_back(temp);
        }
        if(c[i]){
            temp.a = a[i];
            temp.c = c[i];
            temp.h = h[i];
            itm.push_back(temp);
        }
    }
    sort(itm.begin(),itm.end(),cmp);
    n = itm.size();
    f[0] = true;
    for(int i = 0;i < n;i++){
        hc = itm[i].h*itm[i].c;
        for(int j = itm[i].a;j >= itm[i].h;j--){
            if(f[j-hc]) f[j] = true;
            if(f[j]) ans = max(ans,j);
        }
    }
    cout<<ans;
    return 0;
}
时间: 2024-11-04 17:42:37

tyvj1086 Elevator的相关文章

Elevator

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description The highest building in our city has only one elevator. A request list is made up with N positive numbers. The numbers denote at which floors the elevator will s

hdu 1008 elevator

#include<iostream> #include<stdio.h> #include<math.h> #include<algorithm> using namespace std; int main() { int n; while(~scanf("%d",&n)&&n!=0) { int a,b; a=0; int ans=0; for(int i=0;i<n;i++) { scanf("

poj 2392 Space Elevator (多重背包)

Space Elevator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8110   Accepted: 3843 题目大意  :一群牛要上天  用一些石块堆塔  给出石块的种类  及其每个种类的数量 和该种石块能出现的最高高度  和每种石块的数量 求怎么摆放才能堆得最高 多重背包模板题.... 将所有石块排序  把高度低的放下面 #include<iostream> #include<cstdio>

POJ2392Space Elevator(贪心+背包)

Space Elevator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9970   Accepted: 4738 Description The cows are going to space! They plan to achieve orbit by building a sort of space elevator: a giant tower of blocks. They have K (1 <= K <

poj 2392 Space Elevator(多重背包+先排序)

Description The cows are going to space! They plan to achieve orbit by building a sort of space elevator: a giant tower of blocks. They have K (1 <= K <= 400) different types of blocks with which to build the tower. Each block of type i has height h

XTUOJ 1206 Dormitory&#39;s Elevator

Dormitory's Elevator Time Limit : 1000 MS   Memory Limit : 65536 KB Problem Description The new dormitory has N(1≤N≤100000) floors and M(1≤M≤100000)students. In the new dormitory, in order to save student's time as well as encourage student exercise,

1008. Elevator

The highest building in our city has only one elevator. A request list is made up with N positive numbers. The numbers denote at which floors the elevator will stop, in specified order. It costs 6 seconds to move the elevator up one floor, and 4 seco

POJ2392Space Elevator(多重背包)

Space Elevator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8701   Accepted: 4135 Description The cows are going to space! They plan to achieve orbit by building a sort of space elevator: a giant tower of blocks. They have K (1 <= K <

Elevator poj3539

Elevator Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 1072   Accepted: 287 Case Time Limit: 2000MS Description Edward works as an engineer for Non-trivial Elevators: Engineering, Research and Construction (NEERC). His new task is to d