POJ 1609 Tiling Up Blocks
2013-07-24 16:01
302 查看
[b]TilingUpBlocks[/b]
Description
MichaelTheKidreceivesaninterestinggamesetfromhisgrandparentashisbirthdaygift.Insidethegamesetbox,therearentilingblocksandeachblockhasaformasfollows:
Eachtilingblockisassociatedwithtwoparameters(l,m),meaningthattheupperfaceoftheblockispackedwithlprotrudingknobsontheleftandmprotrudingknobsonthemiddle.Correspondingly,thebottomfaceofan(l,m)-blockiscarvedwithlcavingdensontheleftandmdensonthemiddle.
Itiseasilyseenthatan(l,m)-blockcanbetileduponanother(l,m)-block.However,thisisnottheonlywayforustotileuptheblocks.Actually,an(l,m)-blockcanbetileduponanother(l',m')-blockifandonlyifl>=l'andm>=m'.
NowthepuzzlethatMichaelwantstosolveistodecidewhatisthetallesttilingblockshecanmakeoutofthegivennblockswithinhisgamebox.Inotherwords,youaregivenacollectionofnblocksB={b1,b2,...,bn}andeachblockbiisassociatedwithtwoparameters(li,mi).TheobjectiveoftheproblemistodecidethenumberoftallesttilingblocksmadefromB.
Input
Severalsetsoftilingblocks.Theinputsarejustalistofintegers.Foreachsetoftilingblocks,thefirstintegernrepresentsthenumberofblockswithinthegamebox.Followingn,therewillbenlinesspecifyingparametersofblocksinB;eachlinecontainsexactlytwointegers,representingleftandmiddleparametersofthei-thblock,namely,liandmi.Inotherwords,agameboxisjustacollectionofnblocksB={b1,b2,...,bn}andeachblockbiisassociatedwithtwoparameters(li,mi).
Notethatncanbeaslargeas10000andliandmiareintherangefrom1to100.
Anintegern=0(zero)signifiestheendofinput.
Output
ForeachsetoftilingblocksB,outputthenumberofthetallesttilingblockscanbemadeoutofB.Outputasinglestar'*'tosignifytheendof
outputs.
SampleInput
SampleOutput
TimeLimit:1000MS | MemoryLimit:10000K | |
TotalSubmissions:4675 | Accepted:1824 |
MichaelTheKidreceivesaninterestinggamesetfromhisgrandparentashisbirthdaygift.Insidethegamesetbox,therearentilingblocksandeachblockhasaformasfollows:
Eachtilingblockisassociatedwithtwoparameters(l,m),meaningthattheupperfaceoftheblockispackedwithlprotrudingknobsontheleftandmprotrudingknobsonthemiddle.Correspondingly,thebottomfaceofan(l,m)-blockiscarvedwithlcavingdensontheleftandmdensonthemiddle.
Itiseasilyseenthatan(l,m)-blockcanbetileduponanother(l,m)-block.However,thisisnottheonlywayforustotileuptheblocks.Actually,an(l,m)-blockcanbetileduponanother(l',m')-blockifandonlyifl>=l'andm>=m'.
NowthepuzzlethatMichaelwantstosolveistodecidewhatisthetallesttilingblockshecanmakeoutofthegivennblockswithinhisgamebox.Inotherwords,youaregivenacollectionofnblocksB={b1,b2,...,bn}andeachblockbiisassociatedwithtwoparameters(li,mi).TheobjectiveoftheproblemistodecidethenumberoftallesttilingblocksmadefromB.
Input
Severalsetsoftilingblocks.Theinputsarejustalistofintegers.Foreachsetoftilingblocks,thefirstintegernrepresentsthenumberofblockswithinthegamebox.Followingn,therewillbenlinesspecifyingparametersofblocksinB;eachlinecontainsexactlytwointegers,representingleftandmiddleparametersofthei-thblock,namely,liandmi.Inotherwords,agameboxisjustacollectionofnblocksB={b1,b2,...,bn}andeachblockbiisassociatedwithtwoparameters(li,mi).
Notethatncanbeaslargeas10000andliandmiareintherangefrom1to100.
Anintegern=0(zero)signifiestheendofinput.
Output
ForeachsetoftilingblocksB,outputthenumberofthetallesttilingblockscanbemadeoutofB.Outputasinglestar'*'tosignifytheendof
outputs.
SampleInput
3 32 11 23 5 42 24 33 11 55 0
SampleOutput
2 3 * 题目大意:给定n个砖块的长和宽,只有当x2>=x1&&y2>=y1时n2可以放在n1上问最高能落多高。 解题方法:求最大不上升子序列,用动态规划。
#include<stdio.h> #include<iostream> #include<string.h> usingnamespacestd; intmain() { intw[105][105]; intdp[105][105]; intn; while(scanf("%d",&n)!=EOF) { if(n==0) { printf("*\n"); break; } inta,b; memset(w,0,sizeof(w)); memset(dp,0,sizeof(dp)); for(inti=1;i<=n;i++) { scanf("%d%d",&a,&b); w[a][b]++; } for(inti=1;i<=100;i++) { for(intj=1;j<=100;j++) { dp[i][j]=max(dp[i-1][j],dp[i][j-1])+w[i][j]; } } printf("%d\n",dp[100][100]); } return0; }
相关文章推荐
- poj 动态规划DP - 1609 Tiling Up Blocks
- 简单动态规划(POJ 1609 Tiling Up Blocks 解题报告)
- poj 1609 Tiling Up Blocks
- POJ 1609 Tiling Up Blocks.
- poj 1609 Tiling Up Blocks dp入门之记忆化搜索
- poj 1609 Tiling Up Blocks(最长不下降序列)
- Tiling Up Blocks - POJ 1609 dp
- poj 1609 Tiling Up Blocks
- 1609 Tiling Up Blocks 解题报告
- poj&nbsp;1609&nbsp;Tiling&nbsp;Up&nbsp;Blocks(DP)
- POJ 1609 Tilining Up Blocks
- pku1609 Tiling Up Blocks (DP题)
- POJ1609:Tiling Up Blocks(DP)
- POJ1609 Tiling Up Blocks
- poj1609 Tiling Up Blocks
- poj1609——Tiling Up Blocks
- 【蓝桥杯-二维DP】Tiling Up Blocks
- poj 1609 Tiling Up Blocks 动态规划
- poj1609 Tiling Up Blocks
- poj1609 Tiling Up Blocks(LIS)