您的位置:首页 > 其它

poj Space Elevator 2392 (多重背包)

2016-02-26 10:26 507 查看
Space Elevator

Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 10212 Accepted: 4855
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
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: