poj Space Elevator 2392 (多重背包)
2016-02-26 10:26
507 查看
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
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 10212 | Accepted: 4855 |
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
#include<stdio.h> #include<string.h> #include<math.h> #include<algorithm> #define INF 0x3f3f3f3f #define ll long long #define N 40010 using namespace std; struct zz { int h; int num; int mh; }q[410]; int dp ; int cmp(zz a,zz b) { return a.mh<b.mh; } int main() { int n,i,j,k; while(scanf("%d",&n)!=EOF) { for(i=0;i<n;i++) scanf("%d%d%d",&q[i].h,&q[i].mh,&q[i].num); sort(q,q+n,cmp); memset(dp,0,sizeof(dp)); for(i=0;i<n;i++) { for(k=1;k<=q[i].num;k++) { for(j=q[i].mh;j>=q[i].h;j--) { dp[j]=max(dp[j],dp[j-q[i].h]+q[i].h); } } } int ans=0; for(i=0;i<=q[n-1].mh;i++) ans=max(ans,dp[i]); printf("%d\n",ans); } return 0; }
相关文章推荐
- 10024---自定义jsp标签: TagSupport与BodyTagSupport的区别
- 为什么要用内省和BeanUtils以及路径问题
- javascript匿名函数的理解
- 使用virsh调整运行中的KVM虚拟机内存,CPU(centos6.x)
- 纹理内存
- 用 strace 命令浅析 git push 通过 SSH 工作的原理
- 成都Uber优步司机奖励政策(2月26日)
- 类和类的静态变量
- 根据字段条件清理mysql数据库数据
- 二维码小工具使用指南
- activity_显示样式
- python系列之 - 面向对象(一)
- [慢查优化]慎用MySQL子查询,尤其是看到DEPENDENT SUBQUERY标记时(转)
- 后台post get请求
- 欢迎使用CSDN-markdown编辑器
- 如何用ping检测代理服务器状态?
- 使用QTextCodec/QString/QByteArray/std::string时中文编码问题
- PDO简单操作
- AnimatedVectorDrawableCompat适配5.0以下安卓
- c++ static的作用,以及static对象在类和函数中区别