POJ 2392 Space Elevator
2013-08-03 21:42
295 查看
[b]SpaceElevator[/b]
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
SampleOutput
TimeLimit:1000MS | MemoryLimit:65536K | |
TotalSubmissions:7150 | Accepted:3352 |
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; }
相关文章推荐
- POJ 2392 Space Elevator(贪心+多重背包)
- POJ 2392 Space Elevator (dp)
- poj 2392 Space Elevator(多重背包变形)
- poj 2392 Space Elevator
- POJ 2392 Space Elevator
- POJ 2392 Space Elevator(贪心+多重背包)
- poj 2392 Space Elevator (多重背包)
- poj 2392 Space Elevator
- poj 2392 space elevator
- POJ - 2392 Space Elevator(多重背包)
- POJ 2392 Space Elevator(多重背包)
- POJ 2392 Space Elevator(多重背包)
- POJ 2392 Space Elevator
- POJ 2392 Space Elevator
- poj 2392 Space Elevator(多重背包)
- POJ 2392 Space Elevator (多重背包问题)
- POJ 2392 Space Elevator(01背包)
- POJ 2392 Space Elevator
- poj 2392 Space Elevator(dp 排序+多重背包)
- POJ 2392 Space Elevator