BZOJ 1739: [Usaco2005 mar]Space Elevator 太空电梯

题目

1739: [Usaco2005 mar]Space Elevator 太空电梯

Time Limit: 5 Sec  Memory Limit: 64 MB

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_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 other according to the rules.

牛们要到太空去了!他们打算建造一座太空电梯来送他们进入轨道.

有K(1≤K≤400)神方块,第i种有一个特定的高度hi(l≤hi≤100),一定的存量ci(l≤ci≤10).为防宇宙射线的破坏,第i种方块的任何部分不能超过高度ai(l≤ai≤40000). 请用这些方块堆出最高的太空电梯.

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.

第1行输入一个整数K.

接下来K行,每行输入三个整数hi,ai,ci.

Output

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

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

Sample Input

3
7 40 3
5 23 8
2 52 6

Sample Output

48
从底部开始,先放3个方块2,之后3个方块1,接下来6个方块3.不能把3个方块1堆到4个方
块2上,因为这样最高的方块1的顶部高度超过了40.

HINT

Source

Gold

题解

Orz考完小四门的期中考试,来刷刷水题愉悦一下身心!Orz坑爹的生物一共75分钟竟然70道选择题一堆大题,我还好几周没去,呵呵~好的,这道题目其实就是做n遍有限背包~

代码

 1 /*Author:WNJXYK*/
 2 #include<cstdio>
 3 #include<algorithm>
 4 using namespace std;
 5
 6 struct Node{
 7     int c;
 8     int h;
 9     int a;
10 };
11 Node k[405];
12 bool f[40005];
13 bool cmp(Node a,Node b){
14     if (a.a<b.a)return true;
15     return false;
16 }
17 int n;
18 int main(){
19     scanf("%d",&n);
20     for (int i=1;i<=n;i++) scanf("%d%d%d",&k[i].h,&k[i].a,&k[i].c);
21     f[0]=true;
22     sort(k+1,k+n+1,cmp);
23     for (int i=1;i<=n;i++){
24         for (int h=k[i].a;h>=0;h--){
25             for (int j=1;j<=k[i].c&&k[i].h*j+h<=k[i].a;j++){
26                 f[k[i].h*j+h]=f[k[i].h*j+h]||f[h];
27             }
28         }
29     }
30     int Ans=0;
31     for (int i=40000;i>=0;i--)
32         if (f[i]){
33             Ans=i;
34             break;
35         }
36     printf("%d\n",Ans);
37     return 0;
38 }

时间: 2024-08-25 11:10:07

BZOJ 1739: [Usaco2005 mar]Space Elevator 太空电梯的相关文章

BZOJ1739: [Usaco2005 mar]Space Elevator 太空电梯

n<=400个东西,每个东西有高度<=100,这种东西在堆放过程中不得超过的最大高度<=40000,以及每个东西的个数<=10,求最高能堆多高. 算了下背包复杂度不太对然后开了bitset.. 1 #include<stdio.h> 2 #include<string.h> 3 #include<stdlib.h> 4 #include<algorithm> 5 #include<bitset> 6 //#include&

BZOJ 1738: [Usaco2005 mar]Ombrophobic Bovines 发抖的牛( floyd + 二分答案 + 最大流 )

一道水题WA了这么多次真是.... 统考终于完 ( 挂 ) 了...可以好好写题了... 先floyd跑出各个点的最短路 , 然后二分答案 m , 再建图. 每个 farm 拆成一个 cow 点和一个 shelter 点, 然后对于每个 farm x : S -> cow( x ) = cow( x ) 数量 , shelter( x ) -> T = shelter( x ) 容量 ; 对于每个dist( u , v ) <= m 的 cow( u ) -> shelter( v

bzoj:1681: [Usaco2005 Mar]Checking an Alibi 不在场的证明

Description A crime has been comitted: a load of grain has been taken from the barn by one of FJ's cows. FJ is trying to determine which of his C (1 <= C <= 100) cows is the culprit. Fortunately, a passing satellite took an image of his farm M (1 &l

BZOJ 1682: [Usaco2005 Mar]Out of Hay 干草危机

Description 牛们干草要用完了!贝茜打算去勘查灾情. 有N(2≤N≤2000)个农场,M(≤M≤10000)条双向道路连接着它们,长度不超过10^9.每一个农场均与农场1连通.贝茜要走遍每一个农场.她每走一单位长的路,就要消耗一单位的水.从一个农场走到另一个农场,她就要带上数量上等于路长的水.请帮她确定最小的水箱容量.也就是说,确定某一种方案,使走遍所有农场通过的最长道路的长度最小,必要时她可以走回头路. Input 第1行输入两个整数N和M;接下来M行,每行输入三个整数,表示一条道路

BZOJ 1738: [Usaco2005 mar]Ombrophobic Bovines 发抖的牛

Description 约翰的牛们非常害怕淋雨,那会使他们瑟瑟发抖.他们打算安装一个下雨报警器,并且安排了一个撤退计划.他们需要计算最少的让所有牛进入雨棚的时间.    牛们在农场的F(1≤F≤200)个田地上吃草.有P(1≤P≤1500)条双向路连接着这些田地.路很宽,无限量的牛可以通过.田地上有雨棚,雨棚有一定的容量,牛们可以瞬间从这块田地进入这块田地上的雨棚    请计算最少的时间,让每只牛都进入雨棚. Input 第1行:两个整数F和P; 第2到F+1行:第i+l行有两个整数描述第i个田

bzoj 1680\1740 : [Usaco2005 Mar]Yogurt factory 贪心 双倍经验

1680: [Usaco2005 Mar]Yogurt factory Description The cows have purchased a yogurt factory that makes world-famous Yucky Yogurt. Over the next N (1 <= N <= 10,000) weeks, the price of milk and labor will fluctuate weekly such that it will cost the com

1740: [Usaco2005 mar]Yogurt factory 奶酪工厂

1740: [Usaco2005 mar]Yogurt factory 奶酪工厂 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 119  Solved: 100[Submit][Status][Discuss] Description The cows have purchased a yogurt factory that makes world-famous Yucky Yogurt. Over the next N (1 <= N <= 10

poj 2392 Space Elevator (多重背包)

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

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