您的位置:首页 > 其它

POJ 1609 Tiling Up Blocks

2013-07-24 16:01 302 查看
[b]TilingUpBlocks[/b]

TimeLimit:1000MSMemoryLimit:10000K
TotalSubmissions:4675Accepted:1824
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

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;
}



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