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. hdu1710(Binary Tree Traversals)(二叉树遍历)

    Binary Tree Traversals Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

  2. from __future__ import absolute_import

    from __future__ import absolute_import 这样以后:局部的包将不能覆盖全局的包, 本地的包必须使用相对引用了. 例: from celery import Cele ...

  3. jquery json 操作(转)

    原文:http://www.vososo.com/?p=919 Jquery-json 是 jQuery 的一个插件,可轻松实现对象和 JSON 字符串之间的转换.可序列化 JavaScript 对象 ...

  4. 详解下一代开源混合应用框架Reapp(转)

    http://www.iteye.com/news/30269 官网:http://reapp.io/ [开源推荐]Facebook开源的JavaScript库:React http://www.cs ...

  5. Redis 学习资料整理

    菜鸟爬坑--Redis学习与探索(二):Redis的数据类型 http://www.cnblogs.com/codediary/archive/2015/02/20/redisstudy-2.html ...

  6. oracle序列为什么不是从1开始

    问题原因: ·当我们使用序列作为插入数据时,如果使用了“延迟段”技术,则跳过序列的第一个值 ·Oracle从 11.2.0.1版本开始,提供了一个“延迟段创建”特性: 即 当我们创建了新的表(tabl ...

  7. 什么是 Unix 以及它为什么这么重要?

    大多数操作系统可以被划分到两个不同的家族.除了微软的基于Windows NT的操作系统外,几乎所有其他的都可以追溯到Unix. Linux,Mac OS X,Android,iOS,Chrome OS ...

  8. Ubuntu 13.10 Broadcom BCM4313问题

    开始找不到无线网卡,后来不知道怎么就出来了,但是速度很慢.用下面的方法解决的(我也不知道哪条命令起的作用,反正现在正常了): sudo apt-get remove --purge bcmwl-ker ...

  9. JavaOne 2016——观众得以一睹JShell的威力

    导读 在JavaOne 2016的主题演讲中,Java平台组的首席架构师Mark Reinhold指出Java 9并不仅仅是Jigsaw,针对Java 9,一共包含了85个JEP.我在这里会关注一个他 ...

  10. FloatingActionButton增强版,一个按钮跳出多个按钮--第三方开源--FloatingActionButton

      FloatingActionButton项目在github上的主页:https://github.com/futuresimple/android-floating-action-button F ...