POJ 2392 Space Elevator(01背包)
来源:互联网 发布:新东方英语网络教学 编辑:程序博客网 时间:2024/06/16 11:16
Space Elevator
Time Limit: 1000MS
Memory Limit: 65536KTotal Submissions: 12063
Accepted: 5731
Memory Limit: 65536KTotal Submissions: 12063
Accepted: 5731
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.
Help the cows build the tallest space elevator possible by stacking blocks on top of each 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.
* 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 is not legal, since the top of the last type 1 block would exceed height 40.
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 is not legal, since the top of the last type 1 block would exceed height 40.
Source
USACO 2005 March Gold
题目大意:
一群牛要上太空,给出n种石块,每种石块给出单块高度,总高度不能超过的最大值,数量,要求用这些石块能组成
的最大高度
解题思路:
先按高度最高值按从小到大排序,那么再运用01背包时可以得到最优结果
用dp[ i ]=1表示 i 高度是可以用石块组成的
sum[ i ]表示在用一种石块时,达到 i 高度需要的石块数
AC代码
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int dp[40005],sum[40005];struct node{int h,a,c;}f[405];bool cmp(node a,node b){if(a.a<b.a)return true;return false;}int main(){int k;scanf("%d",&k);for(int i=0;i<k;i++){scanf("%d%d%d",&f[i].h,&f[i].a,&f[i].c);}sort(f,f+k,cmp);int ans=0;dp[0]=1;for(int i=0;i<k;i++){memset(sum,0,sizeof(sum));for(int j=f[i].h;j<=f[i].a;j++){if(!dp[j]&&dp[j-f[i].h]&&sum[j-f[i].h]<f[i].c){dp[j]=1;sum[j]=sum[j-f[i].h]+1;if(j>ans)ans=j;}}}printf("%d\n",ans);return 0;}
阅读全文
1 0
- POJ 2392 Space Elevator(01背包)
- POJ 2392 Space Elevator (多重背包)
- poj 2392 Space Elevator (多重背包)
- POJ 2392-Space Elevator(多重背包)
- poj Space Elevator 2392 (多重背包)
- POJ 2392 Space Elevator(多重背包)
- Space Elevator poj 2392(多重背包)
- POJ 2392 Space Elevator(多重背包)
- POJ - 2392 Space Elevator(多重背包)
- poj 2392 Space Elevator(多重背包)
- Space Elevator POJ 2392 01背包/多重背包+二进制
- poj 2392 Space Elevator(未优化的多重背包)
- POJ 2392 Space Elevator (多重背包 + 思路题)
- POJ 题目2392 Space Elevator(多重背包)
- poj 2392 Space Elevator 多重背包
- poj 2392 Space Elevator(多重背包变形)
- POJ 2392 Space Elevator [DP 多重背包]
- POJ 2392 Space Elevator 0-1背包
- Jackson2
- poj3687 Labeling Balls【拓扑排序】
- 写一个函数,求两个整数之和,要求在函数体内不得使用+、-、*、/四则运算符号。
- mysql数据库支持emoji表情
- 集合的划分(状态的叠加)
- POJ 2392 Space Elevator(01背包)
- .NET 操作ZIP文件第三方库DotNetZip
- TCP套接字网络编程实例(二)
- Android提醒微技巧,你真的了解Dialog、Toast和Snackbar吗?
- SpringBoot的理解
- HDU 1004 Let the Balloon Rise
- Windows环境wamp升级PHP版本
- tensorflow tf.equal(x, y, name=None)
- linux 系统下编译mysql源码遇到的问题