【第三弹】【POJ2392】【Space Elevator】【解法一】
2015-07-31 20:18
344 查看
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_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.
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
Sample Output
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.
Source
USACO 2005 March Gold
1. 最大的高度只要在for v的上限限制就好了。
2.如果有n1,n2两个东西,那么x1 <= min(n1.a-n1.h,n2.a-n1.h-n2.h) x2 <=min(n2.a-n2.h,n1.a-n1.h-n2.h)
所以x1 <= n2.a x2 <= n1.a
如果n1.a < n2.a 那么x1 可以包括x2的情形所以嗯。 就这样排序了。
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 9477 | Accepted: 4494 |
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.
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
3 7 40 3 5 23 8 2 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.
Source
USACO 2005 March Gold
1. 最大的高度只要在for v的上限限制就好了。
2.如果有n1,n2两个东西,那么x1 <= min(n1.a-n1.h,n2.a-n1.h-n2.h) x2 <=min(n2.a-n2.h,n1.a-n1.h-n2.h)
所以x1 <= n2.a x2 <= n1.a
如果n1.a < n2.a 那么x1 可以包括x2的情形所以嗯。 就这样排序了。
#include <iostream> #include <cstring> #include <cmath> #include <queue> #include <stack> #include <list> #include <map> #include <set> #include <string> #include <cstdlib> #include <cstdio> #include <algorithm> using namespace std; int K; struct Node { int h,a,c; }; bool cmp(const Node&n1,const Node&n2) { // return (min(n1.a-n1.h,n2.a-n1.h-n2.h)) > (min(n2.a-n2.h,n1.a-n1.h-n2.h)); return n1.a < n2.a; } const int maxn = 410; Node node[maxn]; const int maxv = 40010; int dp[maxv]; int nums[maxv]; int n; int main() { while(scanf("%d",&K) != EOF) { n = -1; memset(dp,0,sizeof(dp)); cout << K <<endl; for(int i=0;i<K;i++) { scanf("%d%d%d",&node[i].h,&node[i].a,&node[i].c); cout << node[i].h << " " << node[i].a << " " << node[i].c <<endl; n = max(n,node[i].a); } sort(node,node+K,cmp); for(int i=0;i<K;i++) { memset(nums,0,sizeof(nums)); for(int j=node[i].h;j<=node[i].a;j++) { if(dp[j] < dp[j-node[i].h] + node[i].h && nums[j-node[i].h] < node[i].c) { dp[j] = dp[j-node[i].h] + node[i].h ; nums[j] = nums[j-node[i].h] + 1; } } } int maxs = -1; for(int i=n;i>=0;i--) { maxs = max(maxs,dp[i]); } printf("%d\n",maxs); } return 0; }
相关文章推荐
- hdu 5212 code 容斥~或者莫比乌斯
- spring整合mongo报错:Timed Out While Waiting For A Server That Matches AnyServerSelector{} After 10000 Ms
- 单源最小路径问题
- 005.block_基础语法
- 关于Yii2中count方法的使用
- Android之——判断当前应用程序是否是用户程序
- Spark API
- 数据库事务隔离级别
- 数字图像学习2
- Number
- 机房重构----C#中将DataTable类型转化为泛型集合
- 探讨read的返回值的三种情况
- Nginx访问日志管理
- java类的特性
- (easy)LeetCode 217.Contains Duplicate
- HDU 4313 Matrix 树状DP
- 每天一个小知识点19(Javascript对象转换成json的函数)
- BlockingQueue中add,offer,put方法区别
- spark RDD的原理
- HUAS Summer Trainning #3~C