Description

Michael The Kid receives an interesting game set from his grandparent as his birthday gift. Inside the game set box, there are n tiling blocks and each block has a form as follows: 

Each tiling block is associated with two parameters (l,m), meaning that the upper face of the block is packed with l protruding knobs on the left and m protruding knobs on the middle. Correspondingly, the bottom face of an (l,m)-block is carved with l caving dens on the left and m dens on the middle. 
It is easily seen that an (l,m)-block can be tiled upon another (l,m)-block. However,this is not the only way for us to tile up the blocks. Actually, an (l,m)-block can be tiled upon another (l',m')-block if and only if l >= l' and m >= m'. 
Now the puzzle that Michael wants to solve is to decide what is the tallest tiling blocks he can make out of the given n blocks within his game box. In other words, you are given a collection of n blocks B = {b1, b2, . . . , bn} and each block bi is associated with two parameters (li,mi). The objective of the problem is to decide the number of tallest tiling blocks made from B. 

Input

Several sets of tiling blocks. The inputs are just a list of integers.For each set of tiling blocks, the first integer n represents the number of blocks within the game box. Following n, there will be n lines specifying parameters of blocks in B; each line contains exactly two integers, representing left and middle parameters of the i-th block, namely, li and mi. In other words, a game box is just a collection of n blocks B = {b1, b2, . . . , bn} and each block bi is associated with two parameters (li,mi). 
Note that n can be as large as 10000 and li and mi are in the range from 1 to 100. 
An integer n = 0 (zero) signifies the end of input.

Output

For each set of tiling blocks B, output the number of the tallest tiling blocks can be made out of B. Output a single star '*' to signify the end of 
outputs.

Sample Input

3
3 2
1 1
2 3
5
4 2
2 4
3 3
1 1
5 5
0

Sample Output

2
3
*

【题意】给出n块积木的左右凹凸的数量,问最高能搭多高;

【思路】dp[i][j]=max(dp[i][j-1],dp[i-1][j])+cnt[i][j];

#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
const int N=;
int dp[N][N];
int cnt[N][N]; int main()
{
int n;
while(~scanf("%d",&n),n)
{
memset(dp,,sizeof(dp));
memset(cnt,,sizeof(cnt));
for(int i=;i<n;i++)
{
int x,y;
scanf("%d%d",&x,&y);
cnt[x][y]++;
}
for(int i=;i<=;i++)
{
for(int j=;j<=;j++)
{
dp[i][j]=max(dp[i-][j],dp[i][j-])+cnt[i][j];
}
}
printf("%d\n",dp[][]);
}
printf("*\n");
return ;
}

Tiling Up Blocks_DP的更多相关文章

  1. Texture tiling and swizzling

    Texture tiling and swizzling 原帖地址:http://fgiesen.wordpress.com If you’re working with images in your ...

  2. 图文详解Unity3D中Material的Tiling和Offset是怎么回事

    图文详解Unity3D中Material的Tiling和Offset是怎么回事 Tiling和Offset概述 Tiling表示UV坐标的缩放倍数,Offset表示UV坐标的起始位置. 这样说当然是隔 ...

  3. POJ3420Quad Tiling(矩阵快速幂)

    Quad Tiling Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3740 Accepted: 1684 Descripti ...

  4. Tri Tiling[HDU1143]

    Tri Tiling Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  5. Tiling 分类: POJ 2015-06-17 15:15 8人阅读 评论(0) 收藏

    Tiling Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8091   Accepted: 3918 Descriptio ...

  6. I - Tri Tiling

      Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status #in ...

  7. POJ2506——Tiling

    Tiling Description In how many ways can you tile a 2xn rectangle by 2x1 or 2x2 tiles? Here is a samp ...

  8. [POJ 3420] Quad Tiling

      Quad Tiling Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3495   Accepted: 1539 Des ...

  9. uva 11270 - Tiling Dominoes(插头dp)

    题目链接:uva 11270 - Tiling Dominoes 题目大意:用1∗2木块将给出的n∗m大小的矩阵填满的方法总数. 解题思路:插头dp的裸题,dp[i][s]表示第i块位置.而且该位置相 ...

随机推荐

  1. HDUOJ--------A simple stone game(尼姆博弈扩展)(2008北京现场赛A题)

    A simple stone game                                                                                  ...

  2. lucene Lock obtain timed out: Lock@

    出错界面: 解决办法: 出现以上异常主要有两种原因: 1.系统正在写索引未完成之前,应用程序关闭 解决方法:删除提示的lock文件后重启应用(最好在应用中捕捉到,自动删除) 2.系统中有多个线程或程序 ...

  3. #ifdef __cplusplus extern "C"

    #ifdef __cplusplus extern "C" { #endif //一段代码 #ifdef __cplusplus } #endif首先,__cplusplus是cp ...

  4. 必须关注的25位知名JavaScript开发者

    必须关注的25位知名JavaScript开发者 发表于2012-08-07 17:30| 16215次阅读| 来源Crossrider Blog| 46 条评论| 作者Crossrider Blog ...

  5. VS输入输出基本操作以及数据类型和类型转换

    (一)   C#项目的组成结构 项目结构 .config ---配置文件(存放配置参数文件) .csproj ---项目文件(管理文件项) .sln   ---解决方案文件(管理项目) .cs   - ...

  6. js——全选框 checkbox

    一直会碰见input 全选框的问题,先整理一种情况: 1. <input id="selectAll" type="checkbox" />全选 2 ...

  7. netbios wins dns LLMNR

    NetBIOS名称 Network Basic Input/Output System  (RFC-1001,1002)网络基本输入/输出系统协议 NetBIOS是一种高级网络接口,最初是在硬件中实 ...

  8. checkbox全选功能

    $("#cb_classType_all").change(function () { if ($(this).is(":checked")) { $(&quo ...

  9. python操作二进制文件

    有的时候需要用python处理二进制数据,比如,存取文件,socket操作时.这时候,可以使用python的struct模块来完成.可以用 struct来处理c语言中的结构体. struct模块中最重 ...

  10. QuartZ的线程锁

                                                                                                ;        ...