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

  1. 3
  2. 3 2
  3. 1 1
  4. 2 3
  5. 5
  6. 4 2
  7. 2 4
  8. 3 3
  9. 1 1
  10. 5 5
  11. 0

Sample Output

  1. 2
  2. 3
  3. *

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

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

  1. #include<iostream>
  2. #include<stdio.h>
  3. #include<string.h>
  4. using namespace std;
  5. const int N=;
  6. int dp[N][N];
  7. int cnt[N][N];
  8.  
  9. int main()
  10. {
  11. int n;
  12. while(~scanf("%d",&n),n)
  13. {
  14. memset(dp,,sizeof(dp));
  15. memset(cnt,,sizeof(cnt));
  16. for(int i=;i<n;i++)
  17. {
  18. int x,y;
  19. scanf("%d%d",&x,&y);
  20. cnt[x][y]++;
  21. }
  22. for(int i=;i<=;i++)
  23. {
  24. for(int j=;j<=;j++)
  25. {
  26. dp[i][j]=max(dp[i-][j],dp[i][j-])+cnt[i][j];
  27. }
  28. }
  29. printf("%d\n",dp[][]);
  30. }
  31. printf("*\n");
  32. return ;
  33. }

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. IO流--流转换

    import java.io.*; //键盘读入 字节流转换成字符流操作 提高效率 public class io { public static void main(String[] args) t ...

  2. A New Tetris Game

    时间限制(普通/Java):1000MS/10000MS     运行内存限制:65536KByte 总提交: 40            测试通过: 12 描述 曾经,Lele和他姐姐最喜欢,玩得最 ...

  3. viewDidLoad && loadView

    viewDidLoad 方法在controller加载了相关的views后被调用,而不论这些views存储在nib文件里还是在loadView函数中生成. loadView 方法在控制器的 view ...

  4. from __future__ import absolute_import

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

  5. Div CSS absolute与relative的区别小结

    absolute:绝对定位,CSS 写法“ position: absolute; ”,它的定位分两种情况,如下: 1. 没有设定 Top.Right.Bottom.Left 的情况,默认依据父级的“ ...

  6. 绑定本地Service并与之通信-----之一

    import android.app.Service;import android.content.Intent;import android.os.Binder;import android.os. ...

  7. Js练习题之查找字符串中出现最多的字符和个数

    如sssfgtdfssddfsssfssss,出现最多的字符是s,出现了12次 传统写法 分析: 1.准备一个空的json,通过循环字符串的每个字符来看,如果json里没有这个字符,就在json里创建 ...

  8. bzoj 1821: [JSOI2010]Group 部落划分 Group

    #include<cstdio> #include<iostream> #include<cmath> #include<algorithm> #def ...

  9. HDU 4888 Redraw Beautiful Drawings(2014 Multi-University Training Contest 3)

    题意:给定n*m个格子,每个格子能填0-k 的整数.然后给出每列之和和每行之和,问有没有解,有的话是不是唯一解,是唯一解输出方案. 思路:网络流,一共 n+m+2个点   源点 到行连流量为 所给的 ...

  10. 常州培训 day3 解题报告

    第一题: 给出数轴正半轴上N个点的坐标和其权值,给出初始体力值M,人一开始在位置0,体力值会随着走过路程的增加而增加,走多少个单位的路消耗多少体力值.到每个点可以打掉,消耗的体力值就是其权值.求 最多 ...