您的位置:首页 > 其它

POJ 2392 Space Elevator

2013-08-03 21:42 295 查看
[b]SpaceElevator[/b]

TimeLimit:1000MSMemoryLimit:65536K
TotalSubmissions:7150Accepted:3352
Description

Thecowsaregoingtospace!Theyplantoachieveorbitbybuildingasortofspaceelevator:agianttowerofblocks.TheyhaveK(1<=K<=400)differenttypesofblockswithwhichtobuildthetower.Eachblockoftypeihasheighth_i(1<=h_i<=100)andisavailableinquantityc_i(1<=c_i<=10).Duetopossibledamagecausedbycosmicrays,nopartofablockoftypeicanexceedamaximumaltitudea_i(1<=a_i<=40000).

Helpthecowsbuildthetallestspaceelevatorpossiblebystackingblocksontopofeachotheraccordingtotherules.
Input

*Line1:Asingleinteger,K

*Lines2..K+1:Eachlinecontainsthreespace-separatedintegers:h_i,a_i,andc_i.Linei+1describesblocktypei.
Output

*Line1:AsingleintegerH,themaximumheightofatowerthatcanbebuilt
SampleInput

3
7403
5238
2526

SampleOutput

48
题目大意:有一群牛要上太空,他们计划建一个太空梯(用一些石头垒),他们有k种不同类型的石头,每一种石头的高度为h,数量为c,由于会受到太空辐射,每一种石头不能超过这种石头能够达到的最大高度a,求解利用这些石头所能修建的太空梯的最高的高度。
解题方法:多重背包,按照a从小到大对数据排序,然后用多重背包。


#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
usingnamespacestd;

typedefstruct
{
inth;
inta;
intc;
}Stone;

intdp[40010];

boolcmp(constStone&s1,constStone&s2)
{
returns1.a<s2.a;
}

intmain()
{
intK;
Stones[405];
scanf("%d",&K);
for(inti=0;i<K;i++)
{
scanf("%d%d%d",&s[i].h,&s[i].a,&s[i].c);
}
sort(s,s+K,cmp);
dp[0]=1;
for(inti=0;i<K;i++)
{
for(intj=s[i].a;j>=0;j--)
{
for(intk=1;k<=s[i].c;k++)
{
if(j-s[i].h*k>=0&&dp[j-s[i].h*k]!=0)
{
dp[j]=1;
}
}
}
}
for(inti=40010;i>=0;i--)
{
if(dp[i])
{
printf("%d\n",i);
break;
}
}
return0;
}



                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: