Tiling Up Blocks

时间限制: 1000ms 内存限制: 10000KB

通过次数: 2总提交次数: 2

问题描述
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:


Figure 1: Michael’s Tiling Block with parameters (3,2).
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.

输入描述
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.
输出描述
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.
样例输入
3
3 2
1 1
2 3
5
4 2
2 4
3 3
1 1
5 5
0

样例输出
2
3
*

来源
Asia Kaohsiung 2003

问题分析:(略)

这个问题和《POJ1609 UVALive2815 UVA1196 ZOJ1787 Tiling Up Blocks【二维最长上升子序列+DP】》是同一个问题,代码直接用就AC了。

程序说明:参见参考链接。

参考链接:POJ1609 UVALive2815 UVA1196 ZOJ1787 Tiling Up Blocks【二维最长上升子序列+DP】

题记:程序做多了,不定哪天遇见似曾相识的。

AC的C++程序如下:

/* POJ1609 UVALive2815 UVA1196 ZOJ1787 Tiling Up Blocks */#include <iostream>
#include <stdio.h>
#include <string.h>using namespace std;const int N = 100;
int cnt[N+1][N+1], dp[N+1][N+1];int main()
{int n, left, mid;while(scanf("%d", &n) != EOF && n) {memset(cnt, 0, sizeof(cnt));memset(dp, 0, sizeof(dp));for(int i=0; i<n; i++) {scanf("%d%d", &left, &mid);cnt[left][mid]++;}// DP计算过程for(int i=1; i<=N; i++)for(int j=1; j<=N; j++)dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) +cnt[i][j];printf("%d\n", dp[N][N]);}printf("*\n");return 0;
}

NUC1776 Tiling Up Blocks【二维最长上升子序列+DP】相关推荐

  1. java ArrayList 套数组,二维不等长数组

    ArrayList 除了装填普通类型外,还能为数组类型.用法是: ArrayList<ArrayList<Double>> arr = new ArrayList<> ...

  2. C++中 二维可变长数组,vector维度的获取

    最近在leetcode练习算法,想用C但是很多简便的功能C都没有, 于是用C++,但是leetcode中,数组给的都是vector,哪怕是二维 就给vector<vector<int> ...

  3. java 二维变长数组_java二维数组如何指定不同长度

    我们知道二维数组,是在一维数组的基础上进行了维度的增加.那么在实际使用的过程中,有时候我们所需要的二维数组,它们其中的维度是不同的,这就需要我们手动的进行设置.下面我们就来一起探究,二维数组在改变维度 ...

  4. [SCOI2014]方伯伯的玉米田 //二维树状数组优化DP

    题目: 方伯伯在自己的农田边散步,他突然发现田里的一排玉米非常的不美.这排玉米一共有N株,它们的高度参差不齐.方伯伯认为单调不下降序列很美,所以他决定先把一些玉米拔高,再把破坏美感的玉米拔除掉,使得剩 ...

  5. Bailian2806 公共子序列【最长公共子序列+DP】

    2806:公共子序列 描述 我们称序列Z = < z1, z2, -, zk >是序列X = < x1, x2, -, xm >的子序列当且仅当存在 严格上升 的序列< ...

  6. Vijos P1571 笨笨的导弹攻击【最长上升子序列+DP】

    背景 在那遥远的地方,有个小目标-- 笨笨:导弹准备! 路人甲:(这么小个目标都要欺负--)老大,导弹只有一部分可以用-- 笨笨:不管那么多,有多少就打多少! 描述 为了彻底打击目标,笨笨要使用足够多 ...

  7. Vijos P1303 导弹拦截【最长上升子序列+DP】

    背景 实中编程者联盟为了培养技术精湛的后备人才,必须从基础题开始训练. 描述 某国为了防御敌国的导弹袭击,研发出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度, ...

  8. HDU1257 最少拦截系统【最长上升子序列+DP】

    问题链接:HDU1257 最少拦截系统. 问题简述:参见上述问题描述. 问题分析:这个问题的本质是求最长上升子序列.与<POJ2533 Longest Ordered Subsequence[最 ...

  9. HDU1087 Super Jumping! Jumping! Jumping!【最长上升子序列+DP】

    问题链接:HDU1087 Super Jumping! Jumping! Jumping!. 问题简述:参见上述问题描述. 问题分析: 这是一个最长上升子序列问题,使用DP算法实现. 定义dp[i]= ...

最新文章

  1. Cytoscape: MCODE增强包的网络模块化分析
  2. 笔记-高项案例题-2016年上-整体管理+风险管理
  3. Git 索引文件(index file)
  4. 数据库SQL语句学习笔记(4)-过滤数据
  5. 云网络丢包故障定位全景指南
  6. 【操作系统】互斥:软件解决方法
  7. web.xml文件的作用
  8. JSP — 知识总结篇《I》【基础语法】
  9. 技术人成长路径之我见
  10. Objective-C 高性能的循环
  11. 5v继电器模块实物接线_一秒看懂基础继电器电路图解
  12. IE8 访问https安全证书错误;导航阻止 解决办法 《转》
  13. Win10 设置默认语言
  14. 牛客网浙江大学机试--找出直系亲属
  15. Mac通过brew安装Nodejs错误:Could not symlink lib/dtrace/node.d
  16. Android动画完全解析--属性动画
  17. 使用python预测基金_使用python先知3 1创建预测
  18. 谷粒商城三阶段课件_谷粒商城分布式基础篇一
  19. 如何将QQ号设置成手机号?
  20. java-面向对象编程-三大特性之封装

热门文章

  1. windows,linux下SVN实现自动更新WEB目录
  2. 有计算机科学与技术专业的大学,开设计算机科学与技术专业的大学有哪些,开设计算机科学与技术专业的大学有哪些...
  3. php mysql 获取排名,Mysql排序获取排名的实例代码
  4. 组装自己的php框架,搭建自己的PHP框架
  5. phoenix表操作
  6. HDFS最基本的操作命令 和基本配置
  7. .sh 编译 java_build-java.sh
  8. php 时间类型int类型,mysql 查询 int类型日期转换成datetime类型
  9. 网页现现实理服务器没有响应,前端_网页编程 HTTP协议(进阶)
  10. 二叉树的概念和基本术语