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. 服务订单SO创建

    FUNCTION Z_SD_SALESORDER_CREATE. *"------------------------------------------------------------ ...

  2. FaceBook Twitter实习生简历求内推

    写在博客里面吧. 有一个朋友,男,博士在读,研究方向为图像处理,计算机视觉相关. 想在在读期间有一些海外实习经历.不知道哪位博友,有相关的人脉,求内推啊.内推成功的话请吃大餐,哈哈!

  3. [示例]创建Student类,输入学生信息并存入字典,将3个存有学生信息的字典存入数组,并计算

    代码: main: #import <Foundation/Foundation.h> #import "Student.h" int main(int argc, c ...

  4. windbg调试C#代码(二)

    这篇主要讲如何分析高内存和高CPU. 1.如何分析高内存 注:如果抓Dump的同时,刚好在执行GC,抓出来的Dump执行命令多半会出错,用!VerifyHeap也能验证Dump有误,这种情况只能重新抓 ...

  5. 'NSInteger' (aka 'long') to 'int32

    怎么去掉Xcode工程中的某种类型的警告 Implicit conversion loses integer precision: 'NSInteger' (aka 'long') to 'int32 ...

  6. 启动BPM的5个步骤

    在大部分业务中,我们通常认为:一个主要的业务流程管理项目从设计时间开始会比较好.我们知道很多方式来提高效率,增加生产力以及简化我们员工的工 作 - 这正是业务流程管理所做的.不幸的是,不管我们意图多好 ...

  7. redis2.8--内存管理

    总而言之,redis内存管理是采用主要由操作系统自主控制内存分配,辅之以简单封装,达到简单且稍微改良的性能. 内存块,标记上本块size 如上图所示, 当调用zmalloc/zmalloc时,输入参数 ...

  8. windows8.1安装

    不小心下载了英文版的windows8.1的操作系统,要添加中文语言,结果遇到不少问题. 第一:安装中文语言包: 可以在控制面板-添加语言中添加,这个方法好像只能在线更新,那速度,不能忍.还可以下载离线 ...

  9. SharePoint 2013 开发——开发并部署webpart

    博客地址:http://blog.csdn.net/FoxDave webpart我们就不详细阐述了,在APP的开发中,自定义属性设置通过APP webpart的URL查询字符串传递,它通过IFR ...

  10. 命令行BASH

    shell 壳,把用户的指令翻译给内核kernel,真正工作的是内核 shell分为cli(command line interface)和gui(graphical user interface) ...